-
-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from jmolivas/Issue-2358493
Patch Issue 2358493 - Integration with Views for entity content generated
- Loading branch information
Showing
8 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Resources/skeleton/module/entity-content-page.php.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{% extends "base/file.php.twig" %} | ||
|
||
{% block file_path %} | ||
{{ entity_name }}.page.inc | ||
{% endblock %} | ||
|
||
{% block extra_info %} | ||
* {{ entity_class }} page callback file for the {{ entity_name }} entity. | ||
{% endblock %} | ||
|
||
{% block use_class %} | ||
use Drupal\Core\Render\Element; | ||
{% endblock %} | ||
|
||
{% block file_methods %} | ||
/** | ||
* Prepares variables for {{ entity_name }} templates. | ||
* | ||
* Default template: {{ entity_name }}.html.twig. | ||
* | ||
* @param array $variables | ||
* An associative array containing: | ||
* - elements: An associative array containing the user information and any | ||
* - attributes: HTML attributes for the containing element. | ||
*/ | ||
|
||
function template_preprocess_{{ entity_name }}(&$variables) { | ||
// Fetch {{ entity_class }} Entity Object | ||
${{ entity_name }} = $variables['elements']['#{{ entity_name }}']; | ||
|
||
// Helpful $content variable for templates. | ||
foreach (Element::children($variables['elements']) as $key) { | ||
$variables['content'][$key] = $variables['elements'][$key]; | ||
} | ||
} | ||
{% endblock %} |
40 changes: 40 additions & 0 deletions
40
src/Resources/skeleton/module/src/Entity/entity-content-views-data.php.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{% extends "base/class.php.twig" %} | ||
|
||
{% block file_path %} | ||
Drupal\{{ module }}\Entity\{{ entity_class }}. | ||
{% endblock %} | ||
|
||
{% block namespace_class %} | ||
namespace Drupal\{{ module }}\Entity; | ||
{% endblock %} | ||
|
||
{% block use_class %} | ||
use Drupal\views\EntityViewsData; | ||
use Drupal\views\EntityViewsDataInterface; | ||
{% endblock %} | ||
|
||
{% block class_declaration %} | ||
/** | ||
* Provides the views data for the {{ entity_class }} entity type. | ||
*/ | ||
class {{ entity_class }}ViewsData extends EntityViewsData implements EntityViewsDataInterface | ||
{% endblock %} | ||
|
||
{% block class_methods %} | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getViewsData() { | ||
$data = parent::getViewsData(); | ||
|
||
$data['{{ entity_name }}']['table']['base'] = array( | ||
'field' => 'id', | ||
'title' => t('{{ entity_class }}'), | ||
'help' => t('The {{ entity_name }} entity ID.'), | ||
); | ||
|
||
return $data; | ||
} | ||
|
||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Resources/skeleton/module/src/Entity/entity-content.theme.php.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% block hook_theme %} | ||
$theme['{{ entity_name }}'] = array( | ||
'render element' => 'elements', | ||
'file' => '{{ entity_name }}.page.inc', | ||
'template' => '{{ entity_name }}', | ||
); | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{ '{#' }} | ||
/** | ||
* @file {{ entity_name }}.html.twig | ||
* Default theme implementation to present {{ entity_class }} data. | ||
* | ||
* This template is used when viewing a {{ entity_name }} entity's page, | ||
* | ||
* | ||
* Available variables: | ||
* - content: A list of content items. Use 'content' to print all content, or | ||
* - attributes: HTML attributes for the container element. | ||
* | ||
* @see template_preprocess_{{ entity_name }}() | ||
* | ||
* @ingroup themeable | ||
*/ | ||
{{ '#}' }} | ||
<div{{ '{{' }} attributes.addClass('{{ entity_name }}') {{ '}}' }}> | ||
{{ '{%' }} if content {{ '%}' }} | ||
{{ '{{' }}- content -{{ '}}' }} | ||
{{ '{%' }} endif {{ '%}' }} | ||
</div> |