Skip to content
Snippets Groups Projects
Commit be231852 authored by Bojan Zivanovic's avatar Bojan Zivanovic
Browse files

Addressed feedback.

- removed the classes to match core behavior.
- started using the link object.
- Added an interface for bundle entity descriptions.
- dawehner's fix for create_bundle_url in the preprocess function.
parent 9b384d82
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Provides expanded entity APIs. * Provides expanded entity APIs.
*/ */
use Drupal\Core\Link;
use Drupal\Core\Url; use Drupal\Core\Url;
/** /**
...@@ -37,19 +38,19 @@ function entity_theme() { ...@@ -37,19 +38,19 @@ function entity_theme() {
function template_preprocess_entity_add_list(&$variables) { function template_preprocess_entity_add_list(&$variables) {
$bundle_type = \Drupal::entityTypeManager()->getDefinition($variables['bundle_type']); $bundle_type = \Drupal::entityTypeManager()->getDefinition($variables['bundle_type']);
$variables += [ $variables += [
'class' => str_replace('_', '-', $bundle_type->getBundleOf()) . '-add-list', 'create_bundle_url' => Url::fromRoute('entity.' . $bundle_type->id() . '.add_form')->toString(),
'create_bundle_url' => Url::fromRoute('entity.' . $bundle_type->id() . '.add_form'),
'bundle_type_label' => $bundle_type->getLowercaseLabel(), 'bundle_type_label' => $bundle_type->getLowercaseLabel(),
]; ];
foreach ($variables['bundles'] as $bundle) { foreach ($variables['bundles'] as $bundle) {
$url = Url::fromRoute($variables['form_route_name'], [$bundle->getEntityTypeId() => $bundle->id()]); $bundle_id = $bundle->id();
$variables['bundles'][$bundle->id()] = [ $variables['bundles'][$bundle_id] = [
'bundle' => $bundle->id(), 'add_link' => Link::createFromRoute($bundle->label(), $variables['form_route_name'], [$bundle_type->id() => $bundle_id]),
'add_link' => \Drupal::l($bundle->label(), $url),
'description' => [
'#markup' => $bundle->getDescription(),
],
]; ];
if ($bundle instanceof \Drupal\entity\Entity\EntityDescriptionInterface) {
$variables['bundles'][$bundle_id]['description'] = [
'#markup' => $bundle->getDescription(),
];
}
} }
} }
<?php
/**
* @file
* Contains \Drupal\entity\Entity\EntityDescriptionInterface.
*/
namespace Drupal\entity\Entity;
/**
* Defines the interface for entities that have a description.
*/
interface EntityDescriptionInterface {
/**
* Gets the entity description.
*
* @return string
* The entity description.
*/
public function getDescription();
/**
* Sets the entity description.
*
* @param string $description
* The entity description.
*
* @return $this
*/
public function setDescription($description);
}
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* Default theme implementation to present a list of available bundles. * Default theme implementation to present a list of available bundles.
* *
* Available variables: * Available variables:
* - class: The entity type specific class. E.g. 'node-add-list'.
* - create_bundle_url: The url to the bundle creation page. * - create_bundle_url: The url to the bundle creation page.
* - bundle_type_label: The lowercase label of the bundle entity type. * - bundle_type_label: The lowercase label of the bundle entity type.
* - bundles: A list of bundles, each with the following properties: * - bundles: A list of bundles, each with the following properties:
...@@ -17,7 +16,7 @@ ...@@ -17,7 +16,7 @@
*/ */
#} #}
{% if bundles is not empty %} {% if bundles is not empty %}
<dl class="entity-add-list {{ class }}"> <dl>
{% for bundle in bundles %} {% for bundle in bundles %}
<dt>{{ bundle.add_link }}</dt> <dt>{{ bundle.add_link }}</dt>
<dd>{{ bundle.description }}</dd> <dd>{{ bundle.description }}</dd>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment