ViewModeFieldFormatter.php in Entity Embed 8
File
src/Plugin/entity_embed/EntityEmbedDisplay/ViewModeFieldFormatter.php
View source
<?php
namespace Drupal\entity_embed\Plugin\entity_embed\EntityEmbedDisplay;
use Drupal\Core\Form\FormStateInterface;
class ViewModeFieldFormatter extends EntityReferenceFieldFormatter {
public function getFieldFormatter() {
if (!isset($this->fieldFormatter)) {
$display = [
'type' => $this
->getFieldFormatterId(),
'settings' => [
'view_mode' => $this
->getPluginDefinition()['view_mode'],
],
'label' => 'hidden',
];
$this->fieldFormatter = $this->formatterPluginManager
->getInstance([
'field_definition' => $this
->getFieldDefinition(),
'view_mode' => '_entity_embed',
'configuration' => $display,
]);
}
return $this->fieldFormatter;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return [];
}
public function getFieldFormatterId() {
return 'entity_reference_entity_view';
}
public function calculateDependencies() {
$definition = $this
->getPluginDefinition();
$view_mode = $definition['view_mode'];
$view_modes = [];
foreach ($definition['entity_types'] as $type) {
$view_modes[] = "{$type}.{$view_mode}";
}
$entity_view_modes = $this->entityTypeManager
->getStorage('entity_view_mode')
->loadMultiple($view_modes);
foreach ($entity_view_modes as $view_mode) {
$this
->addDependency($view_mode
->getConfigDependencyKey(), $view_mode
->getConfigDependencyName());
}
return $this->dependencies;
}
}