You are here

apigee-entity.html.twig in Apigee Edge 8

Generic theme implementation to display an Apigee entity.

Drupal core does not yet provide a generic theme for entities therefore you have to implement your own entity type specific theme. This will change when http://dgo.to/2808481 gets fixed which will introduce a generic template for entities with common preprocess functions and theme suggestions.

Available variables:

  • entity: The entity with limited access to object properties and methods. Only method names starting with "get", "has", or "is" and a few common methods such as "id", "label", and "bundle" are available. For example:

    • entity.getEntityTypeId() will return the entity type ID.
    • entity.hasField('field_example') returns TRUE if the entity includes field_example. (This does not indicate the presence of a value in this field.)

    Calling other methods, such as entity.delete(), will result in an exception. See \Drupal\apigee_edge\Entity\EdgeEntityInterface for a full list of methods.

  • label: The title of the entity.
  • content: All rendered field items. Use {{ content }} to print them all, or print a subset such as {{ content.field_example }}. Use {{ content|without('field_example') }} to temporarily suppress the printing of a given child element.
  • url: Direct URL of the current entity.
  • attributes: HTML attributes for the containing element.
  • title_attributes: Same as attributes, except applied to the main title tag that appears in the template.
  • content_attributes: Same as attributes, except applied to the main content tag that appears in the template.
  • title_prefix: Additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
  • title_suffix: Additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
  • view_mode: View mode; for example, "teaser" or "full".

File

templates/apigee-entity.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Generic theme implementation to display an Apigee entity.
  5. *
  6. * Drupal core does not yet provide a generic theme for entities therefore you
  7. * have to implement your own entity type specific theme. This will change
  8. * when http://dgo.to/2808481 gets fixed which will introduce a generic template
  9. * for entities with common preprocess functions and theme suggestions.
  10. *
  11. * Available variables:
  12. * - entity: The entity with limited access to object properties and methods.
  13. * Only method names starting with "get", "has", or "is" and a few common
  14. * methods such as "id", "label", and "bundle" are available. For example:
  15. * - entity.getEntityTypeId() will return the entity type ID.
  16. * - entity.hasField('field_example') returns TRUE if the entity includes
  17. * field_example. (This does not indicate the presence of a value in this
  18. * field.)
  19. * Calling other methods, such as entity.delete(), will result in an exception.
  20. * See \Drupal\apigee_edge\Entity\EdgeEntityInterface for a full list of
  21. * methods.
  22. * - label: The title of the entity.
  23. * - content: All rendered field items. Use {{ content }} to print them all,
  24. * or print a subset such as {{ content.field_example }}. Use
  25. * {{ content|without('field_example') }} to temporarily suppress the printing
  26. * of a given child element.
  27. * - url: Direct URL of the current entity.
  28. * - attributes: HTML attributes for the containing element.
  29. * - title_attributes: Same as attributes, except applied to the main title
  30. * tag that appears in the template.
  31. * - content_attributes: Same as attributes, except applied to the main
  32. * content tag that appears in the template.
  33. * - title_prefix: Additional output populated by modules, intended to be
  34. * displayed in front of the main title tag that appears in the template.
  35. * - title_suffix: Additional output populated by modules, intended to be
  36. * displayed after the main title tag that appears in the template.
  37. * - view_mode: View mode; for example, "teaser" or "full".
  38. *
  39. * @see \Drupal\apigee_edge\Entity\EdgeEntityViewBuilder::getBuildDefaults()
  40. * @see \Drupal\Core\Entity\EntityViewBuilder::getBuildDefaults()
  41. * @see template_preprocess_apigee_entity()
  42. * @see https://www.drupal.org/project/drupal/issues/2808481
  43. *
  44. * @ingroup themeable
  45. */
  46. #}
  47. {%
  48. set classes = [
  49. 'apigee-entity',
  50. view_mode ? 'apigee-entity--view-mode-' ~ view_mode|clean_class,
  51. entity.getEntityTypeId|clean_class,
  52. view_mode ? entity.getEntityTypeId|clean_class ~ '--view-mode-' ~ view_mode|clean_class,
  53. ]|merge(classes|default([]))
  54. %}
  55. {% block apigee_entity %}
  56. <article role="article"{{ attributes|without('role').addClass(classes) }}>
  57. {% block content %}
  58. {{ title_prefix }}
  59. {% if label and view_mode != 'full' %}
  60. <h2{{ title_attributes }}>
  61. {{ label }}
  62. </h2>
  63. {% endif %}
  64. {{ title_suffix }}
  65. <div{{ content_attributes }}>
  66. {{ content }}
  67. </div>
  68. {% endblock %}
  69. </article>
  70. {% endblock %}