function EntityMethodDeriver::processMethod

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Config/Action/Plugin/ConfigAction/Deriver/EntityMethodDeriver.php \Drupal\Core\Config\Action\Plugin\ConfigAction\Deriver\EntityMethodDeriver::processMethod()

Processes a method to create derivatives.

Parameters

\ReflectionMethod $method: The entity method.

\Drupal\Core\Config\Action\Attribute\ActionMethod $action_attribute: The entity method attribute.

\Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type: The entity type.

array $derivative: The base plugin definition that will used to create the derivative.

1 call to EntityMethodDeriver::processMethod()
EntityMethodDeriver::getDerivativeDefinitions in core/lib/Drupal/Core/Config/Action/Plugin/ConfigAction/Deriver/EntityMethodDeriver.php
Gets the definition of all derivatives of a base plugin.

File

core/lib/Drupal/Core/Config/Action/Plugin/ConfigAction/Deriver/EntityMethodDeriver.php, line 95

Class

EntityMethodDeriver
Derives config action methods from attributed config entity methods.

Namespace

Drupal\Core\Config\Action\Plugin\ConfigAction\Deriver

Code

private function processMethod(\ReflectionMethod $method, ActionMethod $action_attribute, ConfigEntityTypeInterface $entity_type, array $derivative) : void {
    $derivative['admin_label'] = $action_attribute->adminLabel ?: $this->t('@entity_type @method', [
        '@entity_type' => $entity_type->getLabel(),
        '@method' => $method->name,
    ]);
    $derivative['constructor_args'] = [
        'method' => $method->name,
        'exists' => $action_attribute->exists,
        'numberOfParams' => $method->getNumberOfParameters(),
        'numberOfRequiredParams' => $method->getNumberOfRequiredParameters(),
        'pluralized' => FALSE,
    ];
    $derivative['entity_types'] = [
        $entity_type->id(),
    ];
    // Build a config action identifier from the entity type's config
    // prefix  and the method name. For example, the Role entity adds a
    // 'user.role:grantPermission' action.
    $this->addDerivative($method->name, $entity_type, $derivative, $method->name);
    $pluralized_name = match (TRUE) {    is_string($action_attribute->pluralize) => $action_attribute->pluralize,
        $action_attribute->pluralize === FALSE => '',
        default => $this->inflector
            ->pluralize($method->name)[0],
    
    };
    // Add a pluralized version of the plugin.
    if (strlen($pluralized_name) > 0) {
        $derivative['constructor_args']['pluralized'] = TRUE;
        $derivative['admin_label'] = $this->t('@admin_label (multiple calls)', [
            '@admin_label' => $derivative['admin_label'],
        ]);
        $this->addDerivative($pluralized_name, $entity_type, $derivative, $method->name);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.