class UserFormModeController in Form mode manager 8
Controller for specific User entity form mode support.
Hierarchy
- class \Drupal\form_mode_manager\Controller\EntityFormModeBase implements ContainerInjectionInterface uses UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\form_mode_manager\Controller\UserFormModeController
Expanded class hierarchy of UserFormModeController
See also
\Drupal\form_mode_manager\Routing\RouteSubscriber
\Drupal\form_mode_manager\Plugin\Derivative\FormModeManagerLocalAction
\Drupal\form_mode_manager\Plugin\Derivative\FormModeManagerLocalTasks
File
- src/
Controller/ UserFormModeController.php, line 15
Namespace
Drupal\form_mode_manager\ControllerView source
class UserFormModeController extends EntityFormModeBase {
/**
* Provides the entity submission form.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*
* @return array
* A User submission form.
*
* @throws \Exception
* If invalid entity type or form mode not exist.
*/
public function entityAdd(RouteMatchInterface $route_match) {
/* @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $this
->getEntityFromRouteMatch($route_match);
if (empty($entity)) {
$route_entity_type_info = $this
->getEntityTypeFromRouteMatch($route_match);
/* @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $this->entityTypeManager
->getStorage($route_entity_type_info['entity_type_id'])
->create([
$route_entity_type_info['entity_key'] => $route_entity_type_info['bundle'],
]);
}
$form_mode_id = $this->formModeManager
->getFormModeMachineName($route_match
->getRouteObject()
->getOption('parameters')['form_mode']['id']);
$operation = empty($form_mode_id) ? 'register' : $form_mode_id;
if ($entity instanceof EntityInterface) {
return $this->entityFormBuilder
->getForm($entity, $operation);
}
}
/**
* Provides the entity 'edit' form.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*
* @return array
* The entity edit Form.
*/
public function entityEdit(RouteMatchInterface $route_match) {
/* @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $this
->getEntityFromRouteMatch($route_match);
$form_mode_id = $this->formModeManager
->getFormModeMachineName($route_match
->getRouteObject()
->getOption('parameters')['form_mode']['id']);
$operation = empty($form_mode_id) ? 'register' : 'edit_' . $form_mode_id;
if ($entity instanceof EntityInterface) {
return $this
->getForm($entity, $operation);
}
}
/**
* The _title_callback for the entity.add routes.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
* @param string $operation
* Name of current context operation to display title (create/edit).
*
* @return string
* The page title.
*/
public function pageTitle(RouteMatchInterface $route_match, $operation) {
$form_mode_label = $route_match
->getRouteObject()
->getOption('parameters')['form_mode']['label'];
return $this
->t('@op @name as @form_mode_label', [
'@name' => $this
->t('User'),
'@form_mode_label' => $form_mode_label,
'@op' => $operation,
]);
}
/**
* The _title_callback for the entity.add routes.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*
* @return string
* The page title.
*/
public function addPageTitle(RouteMatchInterface $route_match) {
return $this
->pageTitle($route_match, $this
->t('Create'));
}
/**
* The _title_callback for the entity.add routes.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*
* @return string
* The page title.
*/
public function editPageTitle(RouteMatchInterface $route_match) {
return $this
->pageTitle($route_match, $this
->t('Edit'));
}
/**
* Retrieves entity from route match.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return array
* The entity object as determined from the passed-in route match.
*/
protected function getEntityTypeFromRouteMatch(RouteMatchInterface $route_match) {
$parametters = parent::getEntityTypeFromRouteMatch($route_match);
$form_mode = $this->formModeManager
->getFormModeMachineName($route_match
->getRouteObject()
->getOption('parameters')['form_mode']['id']);
$form_mode_definition = $this->formModeManager
->getActiveDisplays($parametters['entity_type_id']);
$parametters['form_mode'] = $form_mode_definition[$form_mode];
return $parametters;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityFormModeBase:: |
protected | property | The current user. | |
EntityFormModeBase:: |
protected | property | The date formatter service. | |
EntityFormModeBase:: |
protected | property | The entity form builder service. | |
EntityFormModeBase:: |
protected | property | The Routes Manager Plugin. | |
EntityFormModeBase:: |
protected | property | The entity type manager service. | |
EntityFormModeBase:: |
protected | property | The form builder. | |
EntityFormModeBase:: |
protected | property | The entity display repository. | |
EntityFormModeBase:: |
protected | property | The renderer service. | |
EntityFormModeBase:: |
public | function | Displays add content links for available entity types. | |
EntityFormModeBase:: |
public | function | Checks access for the Form Mode Manager routes. | |
EntityFormModeBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
EntityFormModeBase:: |
private | function | Get EntityStorage of entity. | |
EntityFormModeBase:: |
protected | function | Retrieves entity from route match. | |
EntityFormModeBase:: |
public | function | Gets the built and processed entity form for the given entity. | |
EntityFormModeBase:: |
public | function | Retrieve the operation (form mode) name in edit context. | |
EntityFormModeBase:: |
public | function | Constructs a EntityFormModeController object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Returns a redirect response object for the specified route. | 3 |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
UserFormModeController:: |
public | function |
The _title_callback for the entity.add routes. Overrides EntityFormModeBase:: |
|
UserFormModeController:: |
public | function |
The _title_callback for the entity.add routes. Overrides EntityFormModeBase:: |
|
UserFormModeController:: |
public | function |
Provides the entity submission form. Overrides EntityFormModeBase:: |
|
UserFormModeController:: |
public | function |
Provides the entity 'edit' form. Overrides EntityFormModeBase:: |
|
UserFormModeController:: |
protected | function |
Retrieves entity from route match. Overrides EntityFormModeBase:: |
|
UserFormModeController:: |
public | function |
The _title_callback for the entity.add routes. Overrides EntityFormModeBase:: |