Issue #2543258 by LKS90, hchonov, tassilogroeper, sasanikolic, Berdir, yched, plach: Entity references of untranslatable fields are not displayed in the correct translation
parent
0cd35ba0d0
commit
d0c13760c6
|
@ -249,7 +249,7 @@ class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayIn
|
||||||
$items = $grouped_items[$id];
|
$items = $grouped_items[$id];
|
||||||
/** @var \Drupal\Core\Access\AccessResultInterface $field_access */
|
/** @var \Drupal\Core\Access\AccessResultInterface $field_access */
|
||||||
$field_access = $items->access('view', NULL, TRUE);
|
$field_access = $items->access('view', NULL, TRUE);
|
||||||
$build_list[$id][$name] = $field_access->isAllowed() ? $formatter->view($items) : [];
|
$build_list[$id][$name] = $field_access->isAllowed() ? $formatter->view($items, $entity->language()->getId()) : [];
|
||||||
// Apply the field access cacheability metadata to the render array.
|
// Apply the field access cacheability metadata to the render array.
|
||||||
$this->renderer->addCacheableDependency($build_list[$id][$name], $field_access);
|
$this->renderer->addCacheableDependency($build_list[$id][$name], $field_access);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Drupal\Core\Field;
|
namespace Drupal\Core\Field;
|
||||||
|
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Drupal\Core\Language\LanguageInterface;
|
||||||
use Drupal\Core\Render\Element;
|
use Drupal\Core\Render\Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,8 +77,12 @@ abstract class FormatterBase extends PluginSettingsBase implements FormatterInte
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function view(FieldItemListInterface $items) {
|
public function view(FieldItemListInterface $items, $langcode = NULL) {
|
||||||
$elements = $this->viewElements($items);
|
// Default the language to the current content language.
|
||||||
|
if (empty($langcode)) {
|
||||||
|
$langcode = \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
|
||||||
|
}
|
||||||
|
$elements = $this->viewElements($items, $langcode);
|
||||||
|
|
||||||
// If there are actual renderable children, use #theme => field, otherwise,
|
// If there are actual renderable children, use #theme => field, otherwise,
|
||||||
// let access cacheability metadata pass through for correct bubbling.
|
// let access cacheability metadata pass through for correct bubbling.
|
||||||
|
|
|
@ -69,23 +69,28 @@ interface FormatterInterface extends PluginSettingsInterface {
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Field\FieldItemListInterface $items
|
* @param \Drupal\Core\Field\FieldItemListInterface $items
|
||||||
* The field values to be rendered.
|
* The field values to be rendered.
|
||||||
|
* @param string $langcode
|
||||||
|
* (optional) The language that should be used to render the field. Defaults
|
||||||
|
* to the current content language.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* A renderable array for a themed field with its label and all its values.
|
* A renderable array for a themed field with its label and all its values.
|
||||||
*/
|
*/
|
||||||
public function view(FieldItemListInterface $items);
|
public function view(FieldItemListInterface $items, $langcode = NULL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a renderable array for a field value.
|
* Builds a renderable array for a field value.
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Field\FieldItemListInterface $items
|
* @param \Drupal\Core\Field\FieldItemListInterface $items
|
||||||
* The field values to be rendered.
|
* The field values to be rendered.
|
||||||
|
* @param string $langcode
|
||||||
|
* The language that should be used to render the field.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* A renderable array for $items, as an array of child elements keyed by
|
* A renderable array for $items, as an array of child elements keyed by
|
||||||
* consecutive numeric indexes starting from 0.
|
* consecutive numeric indexes starting from 0.
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items);
|
public function viewElements(FieldItemListInterface $items, $langcode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if the formatter can be used for the provided field.
|
* Returns if the formatter can be used for the provided field.
|
||||||
|
|
|
@ -30,7 +30,7 @@ class BasicStringFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -116,7 +116,7 @@ class BooleanFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
$formats = $this->getOutputFormats();
|
$formats = $this->getOutputFormats();
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
|
||||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||||
use Drupal\Core\Field\FieldItemListInterface;
|
use Drupal\Core\Field\FieldItemListInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Drupal\Core\Language\LanguageInterface;
|
||||||
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
|
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
|
||||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
@ -119,11 +120,11 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase implem
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$view_mode = $this->getSetting('view_mode');
|
$view_mode = $this->getSetting('view_mode');
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($this->getEntitiesToView($items) as $delta => $entity) {
|
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
|
||||||
// Protect ourselves from recursive rendering.
|
// Protect ourselves from recursive rendering.
|
||||||
static $depth = 0;
|
static $depth = 0;
|
||||||
$depth++;
|
$depth++;
|
||||||
|
|
|
@ -36,24 +36,25 @@ abstract class EntityReferenceFormatterBase extends FormatterBase {
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Field\EntityReferenceFieldItemListInterface $items
|
* @param \Drupal\Core\Field\EntityReferenceFieldItemListInterface $items
|
||||||
* The item list.
|
* The item list.
|
||||||
|
* @param string $langcode
|
||||||
|
* The language code of the referenced entities to display.
|
||||||
*
|
*
|
||||||
* @return \Drupal\Core\Entity\EntityInterface[]
|
* @return \Drupal\Core\Entity\EntityInterface[]
|
||||||
* The array of referenced entities to display, keyed by delta.
|
* The array of referenced entities to display, keyed by delta.
|
||||||
*
|
*
|
||||||
* @see ::prepareView()
|
* @see ::prepareView()
|
||||||
*/
|
*/
|
||||||
protected function getEntitiesToView(EntityReferenceFieldItemListInterface $items) {
|
protected function getEntitiesToView(EntityReferenceFieldItemListInterface $items, $langcode) {
|
||||||
$entities = array();
|
$entities = array();
|
||||||
|
|
||||||
$parent_entity_langcode = $items->getEntity()->language()->getId();
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
// Ignore items where no entity could be loaded in prepareView().
|
// Ignore items where no entity could be loaded in prepareView().
|
||||||
if (!empty($item->_loaded)) {
|
if (!empty($item->_loaded)) {
|
||||||
$entity = $item->entity;
|
$entity = $item->entity;
|
||||||
|
|
||||||
// Set the entity in the correct language for display.
|
// Set the entity in the correct language for display.
|
||||||
if ($entity instanceof TranslatableInterface && $entity->hasTranslation($parent_entity_langcode)) {
|
if ($entity instanceof TranslatableInterface) {
|
||||||
$entity = $entity->getTranslation($parent_entity_langcode);
|
$entity = \Drupal::entityManager()->getTranslationFromContext($entity, $langcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
$access = $this->checkAccess($entity);
|
$access = $this->checkAccess($entity);
|
||||||
|
@ -76,8 +77,8 @@ abstract class EntityReferenceFormatterBase extends FormatterBase {
|
||||||
* @see ::prepareView()
|
* @see ::prepareView()
|
||||||
* @see ::getEntitiestoView()
|
* @see ::getEntitiestoView()
|
||||||
*/
|
*/
|
||||||
public function view(FieldItemListInterface $items) {
|
public function view(FieldItemListInterface $items, $langcode = NULL) {
|
||||||
$elements = parent::view($items);
|
$elements = parent::view($items, $langcode);
|
||||||
|
|
||||||
$field_level_access_cacheability = new CacheableMetadata();
|
$field_level_access_cacheability = new CacheableMetadata();
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
|
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
|
||||||
|
|
||||||
use Drupal\Core\Field\FieldItemListInterface;
|
use Drupal\Core\Field\FieldItemListInterface;
|
||||||
|
use Drupal\Core\Language\LanguageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin implementation of the 'entity reference ID' formatter.
|
* Plugin implementation of the 'entity reference ID' formatter.
|
||||||
|
@ -26,10 +27,10 @@ class EntityReferenceIdFormatter extends EntityReferenceFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($this->getEntitiesToView($items) as $delta => $entity) {
|
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
|
||||||
if ($entity->id()) {
|
if ($entity->id()) {
|
||||||
$elements[$delta] = array(
|
$elements[$delta] = array(
|
||||||
'#plain_text' => $entity->id(),
|
'#plain_text' => $entity->id(),
|
||||||
|
|
|
@ -59,11 +59,11 @@ class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
$output_as_link = $this->getSetting('link');
|
$output_as_link = $this->getSetting('link');
|
||||||
|
|
||||||
foreach ($this->getEntitiesToView($items) as $delta => $entity) {
|
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
|
||||||
$label = $entity->label();
|
$label = $entity->label();
|
||||||
// If the link is to be displayed and the entity has a uri, display a
|
// If the link is to be displayed and the entity has a uri, display a
|
||||||
// link.
|
// link.
|
||||||
|
|
|
@ -27,7 +27,7 @@ class MailToFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ abstract class NumericFormatterBase extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
$settings = $this->getFieldSettings();
|
$settings = $this->getFieldSettings();
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class NumericUnformattedFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -117,7 +117,7 @@ class StringFormatter extends FormatterBase implements ContainerFactoryPluginInt
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
$url = NULL;
|
$url = NULL;
|
||||||
if ($this->getSetting('link_to_entity')) {
|
if ($this->getSetting('link_to_entity')) {
|
||||||
|
|
|
@ -153,7 +153,7 @@ class TimestampAgoFormatter extends FormatterBase implements ContainerFactoryPlu
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -165,7 +165,7 @@ class TimestampFormatter extends FormatterBase implements ContainerFactoryPlugin
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
$date_format = $this->getSetting('date_format');
|
$date_format = $this->getSetting('date_format');
|
||||||
|
|
|
@ -27,7 +27,7 @@ class UriLinkFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ class AggregatorTitleFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
if ($items->getEntity()->getEntityTypeId() == 'aggregator_feed') {
|
if ($items->getEntity()->getEntityTypeId() == 'aggregator_feed') {
|
||||||
|
|
|
@ -30,7 +30,7 @@ class AggregatorXSSFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ class AuthorNameFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -137,7 +137,7 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
$output = array();
|
$output = array();
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class DateTimeCustomFormatter extends DateTimeFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ class DateTimeDefaultFormatter extends DateTimeFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ class DateTimePlainFormatter extends DateTimeFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -107,7 +107,7 @@ class DateTimeTimeAgoFormatter extends FormatterBase implements ContainerFactory
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -17,6 +17,14 @@ use Drupal\simpletest\WebTestBase;
|
||||||
* @group entity_reference
|
* @group entity_reference
|
||||||
*/
|
*/
|
||||||
class EntityReferenceFieldTranslatedReferenceViewTest extends WebTestBase {
|
class EntityReferenceFieldTranslatedReferenceViewTest extends WebTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag indicating whether the field is translatable.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $translatable = TRUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The langcode of the source language.
|
* The langcode of the source language.
|
||||||
*
|
*
|
||||||
|
@ -188,7 +196,7 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends WebTestBase {
|
||||||
'entity_type' => $this->testEntityTypeName,
|
'entity_type' => $this->testEntityTypeName,
|
||||||
'type' => 'entity_reference',
|
'type' => 'entity_reference',
|
||||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||||
'translatable' => TRUE,
|
'translatable' => $this->translatable,
|
||||||
'settings' => array(
|
'settings' => array(
|
||||||
'allowed_values' => array(
|
'allowed_values' => array(
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -38,7 +38,7 @@ class TestFieldApplicableFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
return array('#markup' => 'Nothing to see here');
|
return array('#markup' => 'Nothing to see here');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ class TestFieldDefaultFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ class TestFieldEmptyFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
if ($items->isEmpty()) {
|
if ($items->isEmpty()) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ class TestFieldEmptySettingFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
if (!empty($items)) {
|
if (!empty($items)) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ class TestFieldMultipleFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
if (!empty($items)) {
|
if (!empty($items)) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ class TestFieldNoSettingsFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -75,7 +75,7 @@ class TestFieldPrepareViewFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ abstract class BaseFieldFileFormatterBase extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
$url = NULL;
|
$url = NULL;
|
||||||
|
|
|
@ -34,7 +34,7 @@ class FileSize extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -25,10 +25,10 @@ class GenericFileFormatter extends FileFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($this->getEntitiesToView($items) as $delta => $file) {
|
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
|
||||||
$item = $file->_referringItem;
|
$item = $file->_referringItem;
|
||||||
$elements[$delta] = array(
|
$elements[$delta] = array(
|
||||||
'#theme' => 'file_link',
|
'#theme' => 'file_link',
|
||||||
|
|
|
@ -25,11 +25,11 @@ class RSSEnclosureFormatter extends FileFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$entity = $items->getEntity();
|
$entity = $items->getEntity();
|
||||||
// Add the first file as an enclosure to the RSS item. RSS allows only one
|
// Add the first file as an enclosure to the RSS item. RSS allows only one
|
||||||
// enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure
|
// enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure
|
||||||
foreach ($this->getEntitiesToView($items) as $delta => $file) {
|
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
|
||||||
$entity->rss_elements[] = array(
|
$entity->rss_elements[] = array(
|
||||||
'key' => 'enclosure',
|
'key' => 'enclosure',
|
||||||
'attributes' => array(
|
'attributes' => array(
|
||||||
|
|
|
@ -25,10 +25,10 @@ class TableFormatter extends FileFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
if ($files = $this->getEntitiesToView($items)) {
|
if ($files = $this->getEntitiesToView($items, $langcode)) {
|
||||||
$header = array(t('Attachment'), t('Size'));
|
$header = array(t('Attachment'), t('Size'));
|
||||||
$rows = array();
|
$rows = array();
|
||||||
foreach ($files as $delta => $file) {
|
foreach ($files as $delta => $file) {
|
||||||
|
|
|
@ -25,10 +25,10 @@ class UrlPlainFormatter extends FileFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($this->getEntitiesToView($items) as $delta => $file) {
|
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
|
||||||
$elements[$delta] = array(
|
$elements[$delta] = array(
|
||||||
'#markup' => file_create_url($file->getFileUri()),
|
'#markup' => file_create_url($file->getFileUri()),
|
||||||
'#cache' => array(
|
'#cache' => array(
|
||||||
|
|
|
@ -169,9 +169,9 @@ class ImageFormatter extends ImageFormatterBase implements ContainerFactoryPlugi
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
$files = $this->getEntitiesToView($items);
|
$files = $this->getEntitiesToView($items, $langcode);
|
||||||
|
|
||||||
// Early opt-out if the field is empty.
|
// Early opt-out if the field is empty.
|
||||||
if (empty($files)) {
|
if (empty($files)) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Drupal\image\Plugin\Field\FieldFormatter;
|
namespace Drupal\image\Plugin\Field\FieldFormatter;
|
||||||
|
|
||||||
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
|
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
|
||||||
|
use Drupal\Core\Language\LanguageInterface;
|
||||||
use Drupal\field\FieldConfigInterface;
|
use Drupal\field\FieldConfigInterface;
|
||||||
use Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase;
|
use Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase;
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ abstract class ImageFormatterBase extends FileFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function getEntitiesToView(EntityReferenceFieldItemListInterface $items) {
|
protected function getEntitiesToView(EntityReferenceFieldItemListInterface $items, $langcode) {
|
||||||
// Add the default image if needed.
|
// Add the default image if needed.
|
||||||
if ($items->isEmpty()) {
|
if ($items->isEmpty()) {
|
||||||
$default_image = $this->getFieldSetting('default_image');
|
$default_image = $this->getFieldSetting('default_image');
|
||||||
|
@ -28,7 +29,6 @@ abstract class ImageFormatterBase extends FileFormatterBase {
|
||||||
if (empty($default_image['uuid']) && $this->fieldDefinition instanceof FieldConfigInterface) {
|
if (empty($default_image['uuid']) && $this->fieldDefinition instanceof FieldConfigInterface) {
|
||||||
$default_image = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('default_image');
|
$default_image = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('default_image');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($default_image['uuid']) && $file = \Drupal::entityManager()->loadEntityByUuid('file', $default_image['uuid'])) {
|
if (!empty($default_image['uuid']) && $file = \Drupal::entityManager()->loadEntityByUuid('file', $default_image['uuid'])) {
|
||||||
// Clone the FieldItemList into a runtime-only object for the formatter,
|
// Clone the FieldItemList into a runtime-only object for the formatter,
|
||||||
// so that the fallback image can be rendered without affecting the
|
// so that the fallback image can be rendered without affecting the
|
||||||
|
@ -48,7 +48,7 @@ abstract class ImageFormatterBase extends FileFormatterBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getEntitiesToView($items);
|
return parent::getEntitiesToView($items, $langcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,7 @@ class LinkFormatter extends FormatterBase implements ContainerFactoryPluginInter
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$element = array();
|
$element = array();
|
||||||
$entity = $items->getEntity();
|
$entity = $items->getEntity();
|
||||||
$settings = $this->getSettings();
|
$settings = $this->getSettings();
|
||||||
|
|
|
@ -42,7 +42,7 @@ class LinkSeparateFormatter extends LinkFormatter {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$element = array();
|
$element = array();
|
||||||
$entity = $items->getEntity();
|
$entity = $items->getEntity();
|
||||||
$settings = $this->getSettings();
|
$settings = $this->getSettings();
|
||||||
|
|
|
@ -33,7 +33,7 @@ class OptionsDefaultFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
// Only collect allowed options if there are actually items to display.
|
// Only collect allowed options if there are actually items to display.
|
||||||
|
|
|
@ -32,7 +32,7 @@ class OptionsKeyFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -192,9 +192,9 @@ class ResponsiveImageFormatter extends ImageFormatterBase implements ContainerFa
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
$files = $this->getEntitiesToView($items);
|
$files = $this->getEntitiesToView($items, $langcode);
|
||||||
|
|
||||||
// Early opt-out if the field is empty.
|
// Early opt-out if the field is empty.
|
||||||
if (empty($files)) {
|
if (empty($files)) {
|
||||||
|
|
|
@ -26,8 +26,8 @@ class ResponsiveImageTestFormatter extends ResponsiveImageFormatter {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = parent::viewElements($items);
|
$elements = parent::viewElements($items, $langcode);
|
||||||
// Unset #item_attributes to test that the theme function can handle that.
|
// Unset #item_attributes to test that the theme function can handle that.
|
||||||
foreach ($elements as &$element) {
|
foreach ($elements as &$element) {
|
||||||
if (isset($element['#item_attributes'])) {
|
if (isset($element['#item_attributes'])) {
|
||||||
|
|
|
@ -28,11 +28,11 @@ class EntityReferenceTaxonomyTermRssFormatter extends EntityReferenceFormatterBa
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$parent_entity = $items->getEntity();
|
$parent_entity = $items->getEntity();
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($this->getEntitiesToView($items) as $delta => $entity) {
|
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
|
||||||
$parent_entity->rss_elements[] = array(
|
$parent_entity->rss_elements[] = array(
|
||||||
'key' => 'category',
|
'key' => 'category',
|
||||||
'value' => $entity->label(),
|
'value' => $entity->label(),
|
||||||
|
|
|
@ -83,7 +83,7 @@ trait TaxonomyTranslationTestTrait {
|
||||||
* (optional) If TRUE, create a translatable term reference field. Defaults
|
* (optional) If TRUE, create a translatable term reference field. Defaults
|
||||||
* to FALSE.
|
* to FALSE.
|
||||||
*/
|
*/
|
||||||
protected function setUpTermReferenceField($translatable = FALSE) {
|
protected function setUpTermReferenceField() {
|
||||||
$handler_settings = array(
|
$handler_settings = array(
|
||||||
'target_bundles' => array(
|
'target_bundles' => array(
|
||||||
$this->vocabulary->id() => $this->vocabulary->id(),
|
$this->vocabulary->id() => $this->vocabulary->id(),
|
||||||
|
@ -92,7 +92,7 @@ trait TaxonomyTranslationTestTrait {
|
||||||
);
|
);
|
||||||
$this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
|
$this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
|
||||||
$field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
|
$field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
|
||||||
$field_storage->setTranslatable($translatable);
|
$field_storage->setTranslatable(FALSE);
|
||||||
$field_storage->save();
|
$field_storage->save();
|
||||||
|
|
||||||
entity_get_form_display('node', 'article', 'default')
|
entity_get_form_display('node', 'article', 'default')
|
||||||
|
|
|
@ -50,7 +50,7 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
|
||||||
$this->vocabulary = $this->createVocabulary();
|
$this->vocabulary = $this->createVocabulary();
|
||||||
$this->enableTranslation();
|
$this->enableTranslation();
|
||||||
$this->setUpTerm();
|
$this->setUpTerm();
|
||||||
$this->setUpTermReferenceField(TRUE);
|
$this->setUpTermReferenceField();
|
||||||
$this->setUpNode();
|
$this->setUpNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ class TelephoneLinkFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$element = array();
|
$element = array();
|
||||||
$title_setting = $this->getSetting('title');
|
$title_setting = $this->getSetting('title');
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ class TextDefaultFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
// The ProcessedText element already handles cache context & tag bubbling.
|
// The ProcessedText element already handles cache context & tag bubbling.
|
||||||
|
|
|
@ -70,7 +70,7 @@ class TextTrimmedFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
$render_as_summary = function (&$element) {
|
$render_as_summary = function (&$element) {
|
||||||
|
|
|
@ -30,10 +30,10 @@ class AuthorFormatter extends EntityReferenceFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($this->getEntitiesToView($items) as $delta => $entity) {
|
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
|
||||||
/** @var $referenced_user \Drupal\user\UserInterface */
|
/** @var $referenced_user \Drupal\user\UserInterface */
|
||||||
$elements[$delta] = array(
|
$elements[$delta] = array(
|
||||||
'#theme' => 'username',
|
'#theme' => 'username',
|
||||||
|
|
|
@ -54,7 +54,7 @@ class UserNameFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -28,8 +28,8 @@ class AttachmentTestFormatter extends NumericUnformattedFormatter {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(FieldItemListInterface $items) {
|
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||||
$elements = parent::viewElements($items);
|
$elements = parent::viewElements($items, $langcode);
|
||||||
|
|
||||||
// Add dummy attachments.
|
// Add dummy attachments.
|
||||||
$entity_id = $items->getEntity()->id();
|
$entity_id = $items->getEntity()->id();
|
||||||
|
|
Loading…
Reference in New Issue