EntityReferenceRenderedDisabled.php in Entityreference Rendered Widget 8
File
src/Plugin/Field/FieldWidget/EntityReferenceRenderedDisabled.php
View source
<?php
namespace Drupal\entityreference_rendered_widget\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
class EntityReferenceRenderedDisabled extends EntityReferenceRenderedBase {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
if (empty($items
->get($delta)
->getValue()['target_id'])) {
$element['#markup'] = '<div class="label">' . $element['#title'] . '</div>';
$element['#markup'] .= '<div>' . $this
->t('Value creation for this field is disabled.') . '</div>';
return $element;
}
$target = $this->entityTypeManager
->getStorage($this->targetEntityType)
->load($items
->get($delta)
->getValue()['target_id']);
$view_builder = $this->entityTypeManager
->getViewBuilder($target
->getEntityTypeId());
$element['entity'] = $view_builder
->view($target, $this
->getSetting('display_mode'), $target
->language()
->getId());
return $element;
}
}