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