class EntityPermissionsForm
Same name and namespace in other branches
- 11.x core/modules/user/src/Form/EntityPermissionsForm.php \Drupal\user\Form\EntityPermissionsForm
- 10 core/modules/user/src/Form/EntityPermissionsForm.php \Drupal\user\Form\EntityPermissionsForm
- 9 core/modules/user/src/Form/EntityPermissionsForm.php \Drupal\user\Form\EntityPermissionsForm
Provides the permissions administration form for a bundle.
This class handles bundles that are defined by configuration objects.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\AutowireTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Htmx\HtmxRequestInfoTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\user\Form\UserPermissionsForm extends \Drupal\Core\Form\FormBase
- class \Drupal\user\Form\EntityPermissionsForm extends \Drupal\user\Form\UserPermissionsForm
- class \Drupal\user\Form\UserPermissionsForm extends \Drupal\Core\Form\FormBase
Expanded class hierarchy of EntityPermissionsForm
1 file declares its use of EntityPermissionsForm
- EntityPermissionsFormTest.php in core/
modules/ user/ tests/ src/ Unit/ Form/ EntityPermissionsFormTest.php
File
-
core/
modules/ user/ src/ Form/ EntityPermissionsForm.php, line 22
Namespace
Drupal\user\FormView source
class EntityPermissionsForm extends UserPermissionsForm {
/**
* The configuration entity manager.
*
* @var \Drupal\Core\Config\ConfigManagerInterface
*/
protected $configManager;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The bundle object.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $bundle;
/**
* Constructs a new EntityPermissionsForm.
*
* @param \Drupal\user\PermissionHandlerInterface $permission_handler
* The permission handler.
* @param \Drupal\user\RoleStorageInterface $role_storage
* The role storage.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
* The configuration entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Extension\ModuleExtensionList $module_extension_list
* The module extension list.
*/
public function __construct(PermissionHandlerInterface $permission_handler, RoleStorageInterface $role_storage, ModuleHandlerInterface $module_handler, ConfigManagerInterface $config_manager, EntityTypeManagerInterface $entity_type_manager, ModuleExtensionList $module_extension_list) {
parent::__construct($permission_handler, $role_storage, $module_handler, $module_extension_list);
$this->configManager = $config_manager;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('user.permissions'), $container->get('entity_type.manager')
->getStorage('user_role'), $container->get('module_handler'), $container->get('config.manager'), $container->get('entity_type.manager'), $container->get('extension.list.module'));
}
/**
* {@inheritdoc}
*/
protected function permissionsByProvider() : array {
// Get the names of all config entities that depend on $this->bundle.
$config_name = $this->bundle
->getConfigDependencyName();
$config_entities = $this->configManager
->findConfigEntityDependencies('config', [
$config_name,
]);
$config_names = array_map(fn($dependent_config) => $dependent_config->getConfigDependencyName(), $config_entities);
$config_names[] = $config_name;
// Find all the permissions that depend on $this->bundle.
$permissions = $this->permissionHandler
->getPermissions();
$permissions_by_provider = [];
foreach ($permissions as $permission_name => $permission) {
$required_configs = $permission['dependencies']['config'] ?? [];
if (array_intersect($required_configs, $config_names)) {
$provider = $permission['provider'];
$permissions_by_provider[$provider][$permission_name] = $permission;
}
}
return $permissions_by_provider;
}
/**
* Builds the user permissions administration form for a bundle.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param string $bundle_entity_type
* (optional) The entity type ID.
* @param string|\Drupal\Core\Entity\EntityInterface $bundle
* (optional) Either the bundle name or the bundle object.
*/
public function buildForm(array $form, FormStateInterface $form_state, ?string $bundle_entity_type = NULL, $bundle = NULL) : array {
// Set $this->bundle for use by ::permissionsByProvider().
if ($bundle instanceof EntityInterface) {
$this->bundle = $bundle;
return parent::buildForm($form, $form_state);
}
$this->bundle = $this->entityTypeManager
->getStorage($bundle_entity_type)
->load($bundle);
return parent::buildForm($form, $form_state);
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|
| AutowiredInstanceTrait::createInstanceAutowired | public static | function | Instantiates a new instance of the implementing class using autowiring. | ||
| AutowiredInstanceTrait::getAutowireArguments | private static | function | Resolves arguments for a method using autowiring. | ||
| DependencySerializationTrait::$_entityStorages | protected | property | An array of entity type IDs keyed by the property name of their storages. | ||
| DependencySerializationTrait::$_serviceIds | protected | property | An array of service IDs keyed by property name used for serialization. | ||
| DependencySerializationTrait::__sleep | public | function | 2 | ||
| DependencySerializationTrait::__wakeup | public | function | 2 | ||
| EntityPermissionsForm::$bundle | protected | property | The bundle object. | ||
| EntityPermissionsForm::$configManager | protected | property | The configuration entity manager. | ||
| EntityPermissionsForm::$entityTypeManager | protected | property | The entity type manager service. | ||
| EntityPermissionsForm::buildForm | public | function | Builds the user permissions administration form for a bundle. | Overrides UserPermissionsForm::buildForm | |
| EntityPermissionsForm::create | public static | function | Overrides UserPermissionsForm::create | ||
| EntityPermissionsForm::permissionsByProvider | protected | function | Overrides UserPermissionsForm::permissionsByProvider | ||
| EntityPermissionsForm::__construct | public | function | Constructs a new EntityPermissionsForm. | Overrides UserPermissionsForm::__construct | |
| FormBase::$configFactory | protected | property | The config factory. | 1 | |
| FormBase::$requestStack | protected | property | The request stack. | 1 | |
| FormBase::$routeMatch | protected | property | The route match. | ||
| FormBase::config | protected | function | Retrieves a configuration object. | ||
| FormBase::configFactory | protected | function | Gets the config factory for this form. | 1 | |
| FormBase::container | private | function | Returns the service container. | ||
| FormBase::currentUser | protected | function | Gets the current user. | 2 | |
| FormBase::getRequest | protected | function | Gets the request object. | Overrides HtmxRequestInfoTrait::getRequest | |
| FormBase::getRouteMatch | protected | function | Gets the route match. | ||
| FormBase::logger | protected | function | Gets the logger for a specific channel. | ||
| FormBase::redirect | protected | function | Returns a redirect response object for the specified route. | ||
| FormBase::resetConfigFactory | public | function | Resets the configuration factory. | ||
| FormBase::setConfigFactory | public | function | Sets the config factory for this form. | ||
| FormBase::setRequestStack | public | function | Sets the request stack object to use. | ||
| FormBase::validateForm | public | function | Overrides FormInterface::validateForm | 54 | |
| HtmxRequestInfoTrait::getHtmxCurrentUrl | protected | function | Retrieves the URL of the requesting page from an HTMX request header. | ||
| HtmxRequestInfoTrait::getHtmxPrompt | protected | function | Retrieves the prompt from an HTMX request header. | ||
| HtmxRequestInfoTrait::getHtmxTarget | protected | function | Retrieves the target identifier from an HTMX request header. | ||
| HtmxRequestInfoTrait::getHtmxTrigger | protected | function | Retrieves the trigger identifier from an HTMX request header. | ||
| HtmxRequestInfoTrait::getHtmxTriggerName | protected | function | Retrieves the trigger name from an HTMX request header. | ||
| HtmxRequestInfoTrait::isHtmxBoosted | protected | function | Determines if the request is boosted by HTMX. | ||
| HtmxRequestInfoTrait::isHtmxHistoryRestoration | protected | function | Determines if if the request is for history restoration. | ||
| HtmxRequestInfoTrait::isHtmxRequest | protected | function | Determines if the request is sent by HTMX. | ||
| LoggerChannelTrait::$loggerFactory | protected | property | The logger channel factory service. | ||
| LoggerChannelTrait::getLogger | protected | function | Gets the logger for a specific channel. | ||
| LoggerChannelTrait::setLoggerFactory | public | function | Injects the logger channel factory. | ||
| MessengerTrait::$messenger | protected | property | The messenger. | 26 | |
| MessengerTrait::messenger | public | function | Gets the messenger. | 26 | |
| MessengerTrait::setMessenger | public | function | Sets the messenger. | ||
| RedirectDestinationTrait::$redirectDestination | protected | property | The redirect destination service. | 2 | |
| RedirectDestinationTrait::getDestinationArray | protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | ||
| RedirectDestinationTrait::getRedirectDestination | protected | function | Returns the redirect destination service. | ||
| RedirectDestinationTrait::setRedirectDestination | public | function | Sets the redirect destination service. | ||
| StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
| 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. | 1 | |
| UserPermissionsForm::getFormId | public | function | Overrides FormInterface::getFormId | ||
| UserPermissionsForm::getRoles | protected | function | Gets the roles to display in this form. | 1 | |
| UserPermissionsForm::submitForm | public | function | Overrides FormInterface::submitForm |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.