entity.module in Entity API 8.0
Same filename and directory in other branches
Provides expanded entity APIs.
File
entity.moduleView source
<?php
/**
* @file
* Provides expanded entity APIs.
*/
use Drupal\Core\Url;
/**
* Implements hook_theme().
*/
function entity_theme() {
return [
'entity_add_list' => [
'variables' => [
'bundles' => [],
'bundle_type' => NULL,
],
'template' => 'entity-add-list',
],
];
}
/**
* Prepares variables for the list of available bundles.
*
* Default template: entity-add-list.html.twig.
*
* @param array $variables
* An associative array containing:
* - bundle_type: The entity type of the bundles.
* - bundles: An array of bundles with the label, description, add_link keys.
*/
function template_preprocess_entity_add_list(&$variables) {
$bundle_type = \Drupal::entityTypeManager()
->getDefinition($variables['bundle_type']);
$variables += [
'create_bundle_url' => Url::fromRoute('entity.' . $bundle_type
->id() . '.add_form')
->toString(),
'bundle_type_label' => $bundle_type
->getLowercaseLabel(),
];
foreach ($variables['bundles'] as $bundle_name => $bundle_info) {
$variables['bundles'][$bundle_name]['description'] = [
'#markup' => $bundle_info['description'],
];
}
}
Functions
Name | Description |
---|---|
entity_theme | Implements hook_theme(). |
template_preprocess_entity_add_list | Prepares variables for the list of available bundles. |