You are here

class RouteConditionCreator in Block Visibility Groups 8

Defines the form in-place editor.

Plugin annotation


@ConditionCreator(
  id = "route",
  label = "Route",
  condition_plugin = "request_path"
)

Hierarchy

Expanded class hierarchy of RouteConditionCreator

File

block_visibility_groups_admin/src/Plugin/ConditionCreator/RouteConditionCreator.php, line 16

Namespace

Drupal\block_visibility_groups_admin\Plugin\ConditionCreator
View source
class RouteConditionCreator extends ConditionCreatorBase {

  /**
   * {@inheritdoc}
   */
  public function getNewConditionLabel() {
    $current_path = $this
      ->getPathPattern();
    return $this
      ->t('Current path: @path', [
      '@path' => $current_path,
    ]);
  }

  /**
   * @return mixed|string
   */
  protected function getPathPattern() {
    $route = $this->route
      ->getRouteObject();
    $path = $route
      ->getPath();
    $parameters = $route
      ->compile()
      ->getPathVariables();
    foreach ($parameters as $parameter) {
      $path = str_replace('{' . $parameter . '}', '*', $path);
    }
    return $path;
  }

  /**
   * {@inheritdoc}
   */
  public function createConditionElements() {
    $elements = parent::createConditionElements();
    $elements['condition_config'] = [
      '#type' => 'value',
      '#value' => [
        'pages' => $this
          ->getPathPattern(),
      ],
    ];
    return $elements;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConditionCreatorBase::$pluginManager protected property
ConditionCreatorBase::$route protected property
ConditionCreatorBase::createConditionConfig public function Create condition configuration from form submission. Overrides ConditionCreatorInterface::createConditionConfig 2
ConditionCreatorBase::itemSelected public function Determine if a condition was selected in the form. Overrides ConditionCreatorInterface::itemSelected 2
ConditionCreatorBase::__construct public function RouteConditionCreator constructor. Overrides PluginBase::__construct 1
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.
RouteConditionCreator::createConditionElements public function Create condition elements for form. Overrides ConditionCreatorBase::createConditionElements
RouteConditionCreator::getNewConditionLabel public function Get the label when creating a new condition. Overrides ConditionCreatorInterface::getNewConditionLabel
RouteConditionCreator::getPathPattern protected function
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.