function EntityMethodDeriver::getDerivativeDefinitions

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

Overrides DeriverBase::getDerivativeDefinitions

File

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

Class

EntityMethodDeriver
Derives config action methods from attributed config entity methods.

Namespace

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

Code

public function getDerivativeDefinitions($base_plugin_definition) {
    // Scan all the config entity classes for attributes.
    foreach ($this->entityTypeManager
        ->getDefinitions() as $entity_type) {
        if ($entity_type instanceof ConfigEntityTypeInterface) {
            $reflectionClass = new \ReflectionClass($entity_type->getClass());
            while ($reflectionClass) {
                foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
                    // Only process a method if it is declared on the current class.
                    // Methods on the parent class will be processed later. This allows
                    // for a parent to have an attribute and an overriding class does
                    // not need one. For example,
                    // \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::setComponent()
                    // and \Drupal\Core\Entity\EntityDisplayBase::setComponent().
                    if ($method->getDeclaringClass()
                        ->getName() === $reflectionClass->getName()) {
                        foreach ($method->getAttributes(ActionMethod::class) as $attribute) {
                            $this->processMethod($method, $attribute->newInstance(), $entity_type, $base_plugin_definition);
                        }
                    }
                }
                $reflectionClass = $reflectionClass->getParentClass();
            }
        }
    }
    return $this->derivatives;
}

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