diff --git a/core/config/schema/core.entity.schema.yml b/core/config/schema/core.entity.schema.yml index aab3c1a8b35a..f6442f7ead7b 100644 --- a/core/config/schema/core.entity.schema.yml +++ b/core/config/schema/core.entity.schema.yml @@ -272,3 +272,26 @@ field.formatter.settings.timestamp_ago: type: mapping label: 'Timestamp ago display format settings' +field.formatter.settings.entity_reference_entity_view: + type: mapping + label: 'Entity reference rendered entity display format settings' + mapping: + view_mode: + type: string + label: 'View mode' + link: + type: boolean + label: 'Show links' + +field.formatter.settings.entity_reference_entity_id: + type: mapping + label: 'Entity reference entity ID display format settings' + +field.formatter.settings.entity_reference_label: + type: mapping + label: 'Entity reference label display format settings' + mapping: + link: + type: boolean + label: 'Link label to the referenced entity' + diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php similarity index 55% rename from core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php rename to core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php index 4c09ecf9abf1..1328f65e2745 100644 --- a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php @@ -2,15 +2,17 @@ /** * @file - * Contains \Drupal\entity_reference\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter. + * Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter. */ -namespace Drupal\entity_reference\Plugin\Field\FieldFormatter; +namespace Drupal\Core\Field\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\entity_reference\RecursiveRenderingException; +use Drupal\Core\Logger\LoggerChannelFactoryInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin implementation of the 'entity reference rendered entity' formatter. @@ -24,7 +26,57 @@ use Drupal\entity_reference\RecursiveRenderingException; * } * ) */ -class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase { +class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase implements ContainerFactoryPluginInterface { + + /** + * The logger factory. + * + * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface + */ + protected $loggerFactory; + + /** + * Constructs a StringFormatter instance. + * + * @param string $plugin_id + * The plugin_id for the formatter. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition + * The definition of the field to which the formatter is associated. + * @param array $settings + * The formatter settings. + * @param string $label + * The formatter label display setting. + * @param string $view_mode + * The view mode. + * @param array $third_party_settings + * Any third party settings settings. + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The entity manager. + * @param LoggerChannelFactoryInterface $logger_factory + * The logger factory. + */ + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, LoggerChannelFactoryInterface $logger_factory) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); + $this->loggerFactory = $logger_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $plugin_id, + $plugin_definition, + $configuration['field_definition'], + $configuration['settings'], + $configuration['label'], + $configuration['view_mode'], + $configuration['third_party_settings'], + $container->get('logger.factory') + ); + } /** * {@inheritdoc} @@ -76,7 +128,8 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase { static $depth = 0; $depth++; if ($depth > 20) { - throw new RecursiveRenderingException(format_string('Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.', array('@entity_type' => $entity->getEntityTypeId(), '@entity_id' => $entity->id()))); + $this->loggerFactory->get('entity')->error('Recursive rendering detected when rendering entity @entity_type @entity_id. Aborting rendering.', array('@entity_type' => $entity->getEntityTypeId(), '@entity_id' => $entity->id())); + return $elements; } if ($entity->id()) { diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php similarity index 94% rename from core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php rename to core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php index 153449921f82..0609b18a4db5 100644 --- a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php @@ -2,14 +2,14 @@ /** * @file - * Contains \Drupal\entity_reference\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase. + * Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase. */ -namespace Drupal\entity_reference\Plugin\Field\FieldFormatter; +namespace Drupal\Core\Field\Plugin\Field\FieldFormatter; +use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FormatterBase; use Drupal\Core\TypedData\TranslatableInterface; -use Drupal\Core\Field\FieldItemListInterface; /** * Parent plugin for entity reference formatters. diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceIdFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceIdFormatter.php similarity index 87% rename from core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceIdFormatter.php rename to core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceIdFormatter.php index 98c316680aa7..5b3b1715f9c9 100644 --- a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceIdFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceIdFormatter.php @@ -2,10 +2,10 @@ /** * @file - * Contains \Drupal\entity_reference\Plugin\Field\FieldFormatter\EntityReferenceIdFormatter. + * Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceIdFormatter. */ -namespace Drupal\entity_reference\Plugin\Field\FieldFormatter; +namespace Drupal\Core\Field\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Component\Utility\String; diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php similarity index 95% rename from core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php rename to core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php index 22d0403e025e..dbc89583913f 100644 --- a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php @@ -2,10 +2,10 @@ /** * @file - * Contains \Drupal\entity_reference\Plugin\Field\FieldFormatter\EntityReferenceLabelFormatter. + * Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceLabelFormatter. */ -namespace Drupal\entity_reference\Plugin\Field\FieldFormatter; +namespace Drupal\Core\Field\Plugin\Field\FieldFormatter; use Drupal\Component\Utility\String; use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException; diff --git a/core/modules/entity_reference/config/schema/entity_reference.schema.yml b/core/modules/entity_reference/config/schema/entity_reference.schema.yml index e71c48702e3a..1ee04d191707 100644 --- a/core/modules/entity_reference/config/schema/entity_reference.schema.yml +++ b/core/modules/entity_reference/config/schema/entity_reference.schema.yml @@ -37,29 +37,6 @@ entity_reference.default.handler_settings: type: boolean label: 'Create referenced entities if they don''t already exist' -field.formatter.settings.entity_reference_entity_view: - type: mapping - label: 'Entity reference rendered entity display format settings' - mapping: - view_mode: - type: string - label: 'View mode' - link: - type: boolean - label: 'Show links' - -field.formatter.settings.entity_reference_entity_id: - type: mapping - label: 'Entity reference entity ID display format settings' - -field.formatter.settings.entity_reference_label: - type: mapping - label: 'Entity reference label display format settings' - mapping: - link: - type: boolean - label: 'Link label to the referenced entity' - field.widget.settings.entity_reference_autocomplete_tags: type: mapping label: 'Entity reference autocomplete (Tags style) display format settings' diff --git a/core/modules/entity_reference/src/RecursiveRenderingException.php b/core/modules/entity_reference/src/RecursiveRenderingException.php deleted file mode 100644 index e0fce9c2d81b..000000000000 --- a/core/modules/entity_reference/src/RecursiveRenderingException.php +++ /dev/null @@ -1,14 +0,0 @@ -