Commit 3fe7cb50 authored by alexpott's avatar alexpott

Issue #2404021 by yched, amateescu: entity_reference formatters should be in Core

parent 1c9e1401
......@@ -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'
......@@ -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 @@
* }
* )
*/
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 @@ public function viewElements(FieldItemListInterface $items) {
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()) {
......
......@@ -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.
......
......@@ -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;
......
......@@ -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;
......
......@@ -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'
......
<?php
/**
* @file
* Contains \Drupal\entity_reference\RecursiveRenderingException.
*/
namespace Drupal\entity_reference;
/**
* Exception thrown when the entity view renderer goes into a potentially
* infinite loop.
*/
class RecursiveRenderingException extends \Exception {}
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\entity_reference\Tests\EntityReferenceFormatterTest.
* Contains \Drupal\field\Tests\EntityReference\EntityReferenceFormatterTest.
*/
namespace Drupal\entity_reference\Tests;
namespace Drupal\field\Tests\EntityReference;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\entity_reference\Tests\EntityReferenceItemTest.
* Contains \Drupal\field\Tests\EntityReference\EntityReferenceItemTest.
*/
namespace Drupal\entity_reference\Tests;
namespace Drupal\field\Tests\EntityReference;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldItemListInterface;
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\entity_reference\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;
/**
* Plugin implementation of the 'entity reference taxonomy term RSS' formatter.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment