You are here

class HideIfString in Field Formatter Condition 8

The plugin for check empty fields.

Plugin annotation


@FieldFormatterCondition(
  id = "hide_if_string",
  label = @Translation("Hide when target field contains a string"),
  dsFields = TRUE,
  types = {
    "all"
  }
)

Hierarchy

Expanded class hierarchy of HideIfString

File

src/Plugin/Field/FieldFormatter/Condition/HideIfString.php, line 18

Namespace

Drupal\fico\Plugin\Field\FieldFormatter\Condition
View source
class HideIfString extends FieldFormatterConditionBase {

  /**
   * {@inheritdoc}
   */
  public function alterForm(&$form, $settings) {
    $options = [];
    $fields = $this
      ->getEntityFields($settings['entity_type'], $settings['bundle']);
    $allowed_field_types = fico_text_types();
    foreach ($fields as $field_name => $field) {
      if ($field_name != $settings['field_name'] && in_array($field
        ->getType(), $allowed_field_types)) {
        $options[$field_name] = $field
          ->getLabel();
      }
    }
    $default_target = isset($settings['settings']['target_field']) ? $settings['settings']['target_field'] : NULL;
    $default_string = isset($settings['settings']['string']) ? $settings['settings']['string'] : NULL;
    $form['target_field'] = [
      '#type' => 'select',
      '#title' => t('Select target field'),
      '#options' => $options,
      '#default_value' => $default_target,
    ];
    $form['string'] = array(
      '#type' => 'textfield',
      '#title' => t('Enter target string'),
      '#default_value' => $default_string,
    );
  }

  /**
   * {@inheritdoc}
   */
  public function access(&$build, $field, $settings) {
    $found = fico_string_search($build, $field, $settings);
    if ($found == TRUE) {
      $build[$field]['#access'] = FALSE;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function summary($settings) {
    $options = [];
    $fields = $this
      ->getEntityFields($settings['entity_type'], $settings['bundle']);
    $allowed_field_types = fico_text_types();
    foreach ($fields as $field_name => $field) {
      if ($field_name != $settings['field_name'] && in_array($field
        ->getType(), $allowed_field_types)) {
        $options[$field_name] = $field
          ->label();
      }
    }
    return t('Condition: %condition (%field = "%string")', [
      "%condition" => t('Hide when target field contains a string'),
      '%field' => $options[$settings['settings']['target_field']],
      '%string' => $settings['settings']['string'],
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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
HideIfString::access public function Access control function. Overrides FieldFormatterConditionBase::access
HideIfString::alterForm public function Alter the condition form. Overrides FieldFormatterConditionBase::alterForm
HideIfString::summary public function Return the summary string. Overrides FieldFormatterConditionBase::summary
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