You are here

class HideOnPages in Field Formatter Condition 8

The plugin for check empty fields.

Plugin annotation


@FieldFormatterCondition(
  id = "hide_on_pages",
  label = @Translation("Hide on specific pages"),
  dsFields = FALSE,
  types = {
    "all"
  }
)

Hierarchy

Expanded class hierarchy of HideOnPages

File

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

Namespace

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

  /**
   * {@inheritdoc}
   */
  public function alterForm(&$form, $settings) {
    $default_visibility = isset($settings['settings']['visibility']) ? $settings['settings']['visibility'] : 0;
    $default_pages = isset($settings['settings']['pages']) ? $settings['settings']['pages'] : '';
    $form['visibility'] = array(
      '#title' => t('Type of display'),
      '#type' => 'radios',
      '#options' => array(
        0 => t('All pages except those listed'),
        1 => t('Only the listed pages'),
      ),
      '#default_value' => $default_visibility,
    );
    $form['pages'] = array(
      '#type' => 'textarea',
      '#title' => t('Enter pages'),
      '#cols' => 10,
      '#default_value' => $default_pages,
      '#description' => t("Specify pages by using their paths. Enter one path per line. * is used as wildcard."),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function access(&$build, $field, $settings) {
    $path = \Drupal::service('path.current')
      ->getPath();
    $path = $path[0] == '/' ? substr($path, 1) : $path;
    $page_match = \Drupal::service('path.matcher')
      ->matchPath($path, $settings['settings']['pages']);
    $page_match = !($settings['settings']['visibility'] xor $page_match);
    if ($page_match) {
      $build[$field]['#access'] = FALSE;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function summary($settings) {
    $pages = explode("\n", $settings['settings']['pages']);
    return t("Condition: %condition - %visibility (%settings)", [
      "%condition" => t('Hide on specific pages'),
      "%visibility" => $settings['settings']['visibility'] == 1 ? t('Only the listed pages') : t('All pages except those listed'),
      "%settings" => implode(', ', $pages),
    ]);
  }

}

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
HideOnPages::access public function Access control function. Overrides FieldFormatterConditionBase::access
HideOnPages::alterForm public function Alter the condition form. Overrides FieldFormatterConditionBase::alterForm
HideOnPages::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