function ActionMethod::__construct

Same name in other branches
  1. 10 core/lib/Drupal/Core/Config/Action/Attribute/ActionMethod.php \Drupal\Core\Config\Action\Attribute\ActionMethod::__construct()

Parameters

\Drupal\Core\Config\Action\Exists $exists: Determines behavior of action depending on entity existence.

\Drupal\Core\StringTranslation\TranslatableMarkup|string $adminLabel: The admin label for the user interface.

bool|string $pluralize: Determines whether to create a pluralized version of the method to enable the action to be called multiple times before saving the entity. The default behavior is to create an action with a plural form as determined by \Symfony\Component\String\Inflector\EnglishInflector::pluralize(). For example, 'grantPermission' has a pluralized version of 'grantPermissions'. If a string is provided this will be the full action ID. For example, if the method is called 'addArray' this can be set to 'addMultipleArrays'. Set to FALSE if a pluralized version does not make logical sense.

string|null $name: The name of the action, if it should differ from the method name. Will be pluralized if $pluralize is TRUE. Must follow the rules for a valid PHP function name (e.g., no spaces, no Unicode characters, etc.). If used, the actual name of the method will NOT be available as an action name.

See also

https://www.php.net/manual/en/functions.user-defined.php

File

core/lib/Drupal/Core/Config/Action/Attribute/ActionMethod.php, line 43

Class

ActionMethod
@internal This API is experimental.

Namespace

Drupal\Core\Config\Action\Attribute

Code

public function __construct(Exists $exists = Exists::ErrorIfNotExists, TranslatableMarkup|string $adminLabel = '', bool|string $pluralize = TRUE, ?string $name = NULL) {
    if ($name && !preg_match(ExtensionDiscovery::PHP_FUNCTION_PATTERN, $name)) {
        throw new InvalidPluginDefinitionException('entity_method', sprintf("'%s' is not a valid PHP function name.", $name));
    }
}

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