You are here

class ViewModeFieldFormatter in Entity Embed 8

Entity Embed Display reusing entity reference field formatters.

Plugin annotation


@EntityEmbedDisplay(
  id = "view_mode",
  label = @Translation("View Mode"),
  deriver = "Drupal\entity_embed\Plugin\Derivative\ViewModeDeriver",
  field_type = "entity_reference"
)

Hierarchy

Expanded class hierarchy of ViewModeFieldFormatter

See also

\Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayInterface

File

src/Plugin/entity_embed/EntityEmbedDisplay/ViewModeFieldFormatter.php, line 19

Namespace

Drupal\entity_embed\Plugin\entity_embed\EntityEmbedDisplay
View source
class ViewModeFieldFormatter extends EntityReferenceFieldFormatter {

  /**
   * {@inheritdoc}
   */
  public function getFieldFormatter() {
    if (!isset($this->fieldFormatter)) {
      $display = [
        'type' => $this
          ->getFieldFormatterId(),
        'settings' => [
          'view_mode' => $this
            ->getPluginDefinition()['view_mode'],
        ],
        'label' => 'hidden',
      ];

      // Create the formatter plugin. Will use the default formatter for that
      // field type if none is passed.
      $this->fieldFormatter = $this->formatterPluginManager
        ->getInstance([
        'field_definition' => $this
          ->getFieldDefinition(),
        'view_mode' => '_entity_embed',
        'configuration' => $display,
      ]);
    }
    return $this->fieldFormatter;
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {

    // Configuration form is not needed as the view mode is defined implicitly.
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldFormatterId() {
    return 'entity_reference_entity_view';
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DependencyTrait::$dependencies protected property The object's dependencies.
DependencyTrait::addDependencies protected function Adds multiple dependencies.
DependencyTrait::addDependency protected function Adds a dependency.
EntityEmbedDisplayBase::$attributes public property The attributes on the embedded entity.
EntityEmbedDisplayBase::$context public property The context for the plugin.
EntityEmbedDisplayBase::$entityTypeManager protected property The entity type manager service.
EntityEmbedDisplayBase::$languageManager protected property The language manager.
EntityEmbedDisplayBase::getAttributeValue public function Gets the value for an attribute.
EntityEmbedDisplayBase::getAttributeValues public function Gets the values for all attributes.
EntityEmbedDisplayBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
EntityEmbedDisplayBase::getConfigurationValue public function Gets a configuration value.
EntityEmbedDisplayBase::getContextValue public function Gets the value for a defined context.
EntityEmbedDisplayBase::getContextValues public function Gets the values for all defined contexts.
EntityEmbedDisplayBase::getEntityFromContext public function Gets the entity from the current context.
EntityEmbedDisplayBase::getEntityTypeFromContext public function Gets the entity type from the current context.
EntityEmbedDisplayBase::getLangcode public function Gets the current language code.
EntityEmbedDisplayBase::hasAttribute public function Checks if an attribute is set.
EntityEmbedDisplayBase::hasContextValue public function Returns whether or not value is set for a defined context.
EntityEmbedDisplayBase::isValidEntityType protected function Validates that this display plugin applies to the current entity type.
EntityEmbedDisplayBase::setAttributes public function Sets the values for all attributes.
EntityEmbedDisplayBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
EntityEmbedDisplayBase::setContextValue public function Sets the value for a defined context.
EntityEmbedDisplayBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 1
EntityEmbedDisplayBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
EntityReferenceFieldFormatter::$configFactory protected property The configuration factory.
EntityReferenceFieldFormatter::build public function Builds the renderable array for this Entity Embed display plugin. Overrides FieldFormatterEntityEmbedDisplayBase::build
EntityReferenceFieldFormatter::create public static function Creates an instance of the plugin. Overrides FieldFormatterEntityEmbedDisplayBase::create 1
EntityReferenceFieldFormatter::disableContextualLinks public static function Disables Contextual Links for the embedded media by removing its property.
EntityReferenceFieldFormatter::disableQuickEdit public static function Disables Quick Edit for the embedded media by removing its attributes.
EntityReferenceFieldFormatter::getFieldDefinition public function Get the FieldDefinition object required to render this field's formatter. Overrides FieldFormatterEntityEmbedDisplayBase::getFieldDefinition
EntityReferenceFieldFormatter::getFieldValue public function Get the field value required to pass into the field formatter. Overrides FieldFormatterEntityEmbedDisplayBase::getFieldValue 1
EntityReferenceFieldFormatter::isApplicableFieldFormatter protected function Checks if the field formatter is applicable. Overrides FieldFormatterEntityEmbedDisplayBase::isApplicableFieldFormatter
EntityReferenceFieldFormatter::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
EntityReferenceFieldFormatter::__construct public function Constructs a new EntityReferenceFieldFormatter. Overrides FieldFormatterEntityEmbedDisplayBase::__construct 1
FieldFormatterEntityEmbedDisplayBase::$fieldDefinition protected property The field definition.
FieldFormatterEntityEmbedDisplayBase::$fieldFormatter protected property The field formatter.
FieldFormatterEntityEmbedDisplayBase::$formatterPluginManager protected property The field formatter plugin manager.
FieldFormatterEntityEmbedDisplayBase::$typedDataManager protected property The typed data manager.
FieldFormatterEntityEmbedDisplayBase::access public function Indicates whether this Entity Embed display can be used. Overrides EntityEmbedDisplayBase::access 1
FieldFormatterEntityEmbedDisplayBase::createFieldDefinition protected function Creates a new faux-field definition.
FieldFormatterEntityEmbedDisplayBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides EntityEmbedDisplayBase::defaultConfiguration 1
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginDependencyTrait::calculatePluginDependencies protected function Calculates and adds dependencies of a specific plugin instance. 1
PluginDependencyTrait::getPluginDependencies protected function Calculates and returns dependencies of a specific plugin instance.
PluginDependencyTrait::moduleHandler protected function Wraps the module handler. 1
PluginDependencyTrait::themeHandler protected function Wraps the theme handler. 1
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.
ViewModeFieldFormatter::buildConfigurationForm public function Form constructor. Overrides FieldFormatterEntityEmbedDisplayBase::buildConfigurationForm
ViewModeFieldFormatter::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides FieldFormatterEntityEmbedDisplayBase::calculateDependencies
ViewModeFieldFormatter::getFieldFormatter public function Constructs a field formatter. Overrides FieldFormatterEntityEmbedDisplayBase::getFieldFormatter
ViewModeFieldFormatter::getFieldFormatterId public function Returns the field formatter id. Overrides FieldFormatterEntityEmbedDisplayBase::getFieldFormatterId