You are here

abstract class FieldFormatterConditionBase in Field Formatter Condition 8

Base class for Field formatter condition plugins.

Hierarchy

Expanded class hierarchy of FieldFormatterConditionBase

10 files declare their use of FieldFormatterConditionBase
HideDateTime.php in src/Plugin/Field/FieldFormatter/Condition/HideDateTime.php
HideIfAuthor.php in src/Plugin/Field/FieldFormatter/Condition/HideIfAuthor.php
HideIfBoolCheck.php in src/Plugin/Field/FieldFormatter/Condition/HideIfBoolCheck.php
HideIfEmpty.php in src/Plugin/Field/FieldFormatter/Condition/HideIfEmpty.php
HideIfString.php in src/Plugin/Field/FieldFormatter/Condition/HideIfString.php

... See full list

File

src/Plugin/FieldFormatterConditionBase.php, line 11

Namespace

Drupal\fico\Plugin
View source
abstract class FieldFormatterConditionBase extends PluginBase implements FieldFormatterConditionInterface {

  /**
   * {@inheritdoc}
   */
  public function getDefinition($plugin_id, $exception_on_invalid = TRUE) {
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinitions() {
  }

  /**
   * {@inheritdoc}
   */
  public function hasDefinition($plugin_id) {
  }

  /**
   * {@inheritdoc}
   */
  public function createInstance($plugin_id, array $configuration = []) {
  }

  /**
   * {@inheritdoc}
   */
  public function getInstance(array $options) {
  }

  /**
   * Alter the condition form.
   *
   * @param array $form
   *   Condition formular.
   * @param array $settings
   *   Settings array.
   */
  public abstract function alterForm(&$form, $settings);

  /**
   * Access control function.
   *
   * @param array $build
   *   The current build array.
   * @param string $field
   *   The current field name.
   * @param array $settings
   *   The current settings array.
   */
  public abstract function access(&$build, $field, $settings);

  /**
   * Return the summary string.
   *
   * @param array $settings
   *   The current settings array.
   */
  public abstract function summary($settings);

  /**
   * Check for entity_type in build.
   *
   * @param array $build
   *   The current build array.
   */
  protected function getEntityType(array $build) {
    if (isset($build['#entity_type'])) {
      return $build['#entity_type'];
    }
    $types = \Drupal::entityManager()
      ->getDefinitions();
    foreach ($types as $id => $type) {
      if (!is_a($type, 'Drupal\\Core\\Entity\\ContentEntityType')) {
        continue;
      }
      if (isset($build['#' . $id])) {
        return $id;
      }
    }
    return NULL;
  }

  /**
   * Check for entity in build.
   *
   * @param array $build
   *   The current build array.
   */
  protected function getEntity(array $build) {
    if (!($type = $this
      ->getEntityType($build))) {
      return FALSE;
    }
    return is_object($build['#' . $this
      ->getEntityType($build)]) ? $build['#' . $this
      ->getEntityType($build)] : NULL;
  }

  /**
   * Load fields from a entity.
   *
   * @param string $entity_type
   *   Type of entity.
   * @param string $bundle
   *   Entity bundle.
   *
   * @return array
   *   Returns the field definitions.
   */
  protected function getEntityFields($entity_type, $bundle) {
    $fields = [];
    $entityManager = \Drupal::service('entity.manager');
    if (!empty($entity_type) && !empty($bundle)) {
      $fields = array_filter($entityManager
        ->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
        return $field_definition instanceof FieldConfigInterface;
      });
    }
    return $fields;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldFormatterConditionBase::access abstract public function Access control function. 10
FieldFormatterConditionBase::alterForm abstract public function Alter the condition form. 10
FieldFormatterConditionBase::createInstance public function Creates a pre-configured instance of a plugin. Overrides FactoryInterface::createInstance
FieldFormatterConditionBase::getDefinition public function Gets a specific plugin definition. Overrides DiscoveryInterface::getDefinition
FieldFormatterConditionBase::getDefinitions public function Gets the definition of all plugins for this type. Overrides DiscoveryInterface::getDefinitions
FieldFormatterConditionBase::getEntity protected function Check for entity in build.
FieldFormatterConditionBase::getEntityFields protected function Load fields from a entity.
FieldFormatterConditionBase::getEntityType protected function Check for entity_type in build.
FieldFormatterConditionBase::getInstance public function Gets a preconfigured instance of a plugin. Overrides MapperInterface::getInstance
FieldFormatterConditionBase::hasDefinition public function Indicates if a specific plugin definition exists. Overrides DiscoveryInterface::hasDefinition
FieldFormatterConditionBase::summary abstract public function Return the summary string. 10
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.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92