class MentionsTypeForm in Open Social 10.3.x
Same name and namespace in other branches
- 8.9 modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 8 modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 8.2 modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 8.3 modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 8.4 modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 8.5 modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 8.6 modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 8.7 modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 8.8 modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 10.0.x modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 10.1.x modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
- 10.2.x modules/custom/mentions/src/Form/MentionsTypeForm.php \Drupal\mentions\Form\MentionsTypeForm
Class MentionsTypeForm.
@package Drupal\mentiona\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
- class \Drupal\mentions\Form\MentionsTypeForm implements ContainerInjectionInterface uses ConfigFormBaseTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
Expanded class hierarchy of MentionsTypeForm
2 string references to 'MentionsTypeForm'
- mentions.routing.yml in modules/
custom/ mentions/ mentions.routing.yml - modules/custom/mentions/mentions.routing.yml
- mentions.routing.yml in modules/
custom/ mentions/ mentions.routing.yml - modules/custom/mentions/mentions.routing.yml
File
- modules/
custom/ mentions/ src/ Form/ MentionsTypeForm.php, line 21
Namespace
Drupal\mentions\FormView source
class MentionsTypeForm extends EntityForm implements ContainerInjectionInterface {
use ConfigFormBaseTrait;
/**
* The mentions plugin manager.
*
* @var \Drupal\mentions\MentionsPluginManager
*/
protected $mentionsManager;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity type repository service.
*
* @var \Drupal\Core\Entity\EntityTypeRepositoryInterface
*/
protected $entityTypeRepository;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* {@inheritdoc}
*/
public function __construct(MentionsPluginManager $mentions_manager, EntityTypeManagerInterface $entity_type_manager, EntityTypeRepositoryInterface $entity_type_repository, ModuleHandlerInterface $module_handler) {
$this->mentionsManager = $mentions_manager;
$this->entityTypeManager = $entity_type_manager;
$this->entityTypeRepository = $entity_type_repository;
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.mentions'), $container
->get('entity_type.manager'), $container
->get('entity_type.repository'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'mentions.mentions_type',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'mentions_type_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$plugin_names = $this->mentionsManager
->getPluginNames();
$entity = $this->entity;
$inputsettings = $entity
->get('input');
$entity_id = isset($entity) ? $entity
->id() : '';
$all_entitytypes = array_keys($this->entityTypeRepository
->getEntityTypeLabels());
$candidate_entitytypes = [];
foreach ($all_entitytypes as $entity_type) {
$entitytype_info = $this->entityTypeManager
->getDefinition($entity_type);
$configentityclassname = ContentEntityType::class;
$entitytype_type = get_class($entitytype_info);
if ($entitytype_type == $configentityclassname) {
$candidate_entitytypes[$entity_type] = $entitytype_info
->getLabel()
->getUntranslatedString();
$candidate_entitytypefields[$entity_type][$entitytype_info
->getKey('id')] = $entitytype_info
->getKey('id');
if ($entity_type === 'user') {
$candidate_entitytypefields[$entity_type]['name'] = 'name';
}
else {
$candidate_entitytypefields[$entity_type][$entitytype_info
->getKey('label')] = $entitytype_info
->getKey('label');
}
}
}
$config = $this
->config('mentions.mentions_type.' . $entity_id);
$form['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Name'),
'#required' => TRUE,
'#description' => $this
->t('The human-readable name of this mention type. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'),
'#default_value' => $config
->get('name'),
];
$form['mention_type'] = [
'#type' => 'select',
'#title' => $this
->t('Mention Type'),
'#options' => $plugin_names,
'#default_value' => $config
->get('mention_type'),
];
$form['description'] = [
'#type' => 'textarea',
'#title' => $this
->t('Description'),
'#description' => $this
->t('Describe this mention type.'),
'#default_value' => $config
->get('description'),
];
$form['input'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Input Settings'),
'#tree' => TRUE,
];
$form['input']['prefix'] = [
'#type' => 'textfield',
'#title' => $this
->t('Prefix'),
'#default_value' => $config
->get('input.prefix'),
'#size' => 2,
];
$form['input']['suffix'] = [
'#type' => 'textfield',
'#title' => $this
->t('Suffix'),
'#default_value' => $config
->get('input.suffix'),
'#size' => 2,
];
$entitytype_selection = $config
->get('input.entity_type');
$form['input']['entity_type'] = [
'#type' => 'select',
'#title' => $this
->t('Entity Type'),
'#options' => $candidate_entitytypes,
'#default_value' => $entitytype_selection,
'#ajax' => [
'callback' => [
$this,
'changeEntityTypeInForm',
],
'wrapper' => 'edit-input-value-wrapper',
'event' => 'change',
'progress' => [
'type' => 'throbber',
'message' => $this
->t('Please wait...'),
],
],
];
if (!isset($candidate_entitytypefields)) {
$inputvalue_options = [];
}
elseif (isset($entitytype_selection)) {
$inputvalue_options = $candidate_entitytypefields[$entitytype_selection];
}
else {
$inputvalue_options = array_values($candidate_entitytypefields)[0];
}
$inputvalue_default_value = count($inputsettings) == 0 ? 0 : $inputsettings['inputvalue'];
$form['input']['inputvalue'] = [
'#type' => 'select',
'#title' => $this
->t('Value'),
'#options' => $inputvalue_options,
'#default_value' => $inputvalue_default_value,
'#prefix' => '<div id="edit-input-value-wrapper">',
'#suffix ' => '</div>',
'#validated' => 1,
];
$form['output'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Output Settings'),
'#tree' => TRUE,
];
$form['output']['outputvalue'] = [
'#type' => 'textfield',
'#title' => $this
->t('Value'),
'#description' => $this
->t('This field supports tokens.'),
'#default_value' => $config
->get('output.outputvalue'),
];
$form['output']['renderlink'] = [
'#type' => 'checkbox',
'#title' => 'Render as link',
'#default_value' => $config
->get('output.renderlink'),
];
$form['output']['renderlinktextbox'] = [
'#type' => 'textfield',
'#title' => $this
->t('Link'),
'#description' => $this
->t('This field supports tokens.'),
'#default_value' => $config
->get('output.renderlinktextbox'),
'#states' => [
'visible' => [
':input[name="output[renderlink]"]' => [
'checked' => TRUE,
],
],
],
];
if ($this->moduleHandler
->moduleExists('token')) {
$form['output']['tokens'] = [
'#theme' => 'token_tree_link',
'#token_types' => 'all',
'#show_restricted' => TRUE,
'#theme_wrappers' => [
'form_element',
],
];
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this
->t('Save Mentions Type');
return $actions;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$form_state
->setRedirect('entity.mentions_type.list');
}
/**
* {@inheritdoc}
*/
public function changeEntityTypeInForm(array &$form, FormStateInterface $form_state) {
$entitytype_state = $form_state
->getValue([
'input',
'entity_type',
]);
$entitytype_info = $this->entityTypeManager
->getDefinition($entitytype_state);
$id = $entitytype_info
->getKey('id');
$label = $entitytype_info
->getKey('label');
if ($entitytype_state == 'user') {
$label = 'name';
}
unset($form['input']['inputvalue']['#options']);
unset($form['input']['inputvalue']['#default_value']);
$form['input']['inputvalue']['#options'][$id] = $id;
$form['input']['inputvalue']['#options'][$label] = $label;
$form['input']['inputvalue']['#default_value'] = $id;
return $form['input']['inputvalue'];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityForm:: |
protected | property | The entity being used by this form. | 11 |
EntityForm:: |
protected | property | The name of the current operation. | |
EntityForm:: |
protected | function | Returns the action form element for the current entity form. | |
EntityForm:: |
public | function | Form element #after_build callback: Updates the entity with submitted data. | |
EntityForm:: |
public | function |
Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface:: |
3 |
EntityForm:: |
protected | function | Copies top-level form values to entity properties. | 9 |
EntityForm:: |
public | function | Gets the actual form array to be built. | 36 |
EntityForm:: |
public | function |
Returns a string identifying the base form. Overrides BaseFormIdInterface:: |
6 |
EntityForm:: |
public | function |
Gets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface:: |
3 |
EntityForm:: |
public | function |
Gets the operation identifying the form. Overrides EntityFormInterface:: |
|
EntityForm:: |
protected | function | Initialize the form state and the entity before the first form build. | 3 |
EntityForm:: |
protected | function | Prepares the entity object before the form is built first. | 3 |
EntityForm:: |
protected | function | Invokes the specified prepare hook variant. | |
EntityForm:: |
public | function | Process callback: assigns weights and hides extra fields. | |
EntityForm:: |
public | function |
Form submission handler for the 'save' action. Overrides EntityFormInterface:: |
47 |
EntityForm:: |
public | function |
Sets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity type manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the module handler for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the operation for this form. Overrides EntityFormInterface:: |
|
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MentionsTypeForm:: |
protected | property |
The entity type manager service. Overrides EntityForm:: |
|
MentionsTypeForm:: |
protected | property | The entity type repository service. | |
MentionsTypeForm:: |
protected | property | The mentions plugin manager. | |
MentionsTypeForm:: |
protected | property |
The module handler service. Overrides EntityForm:: |
|
MentionsTypeForm:: |
protected | function |
Returns an array of supported actions for the current entity form. Overrides EntityForm:: |
|
MentionsTypeForm:: |
public | function |
Form constructor. Overrides EntityForm:: |
|
MentionsTypeForm:: |
public | function | ||
MentionsTypeForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
MentionsTypeForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
MentionsTypeForm:: |
public | function |
Returns a unique string identifying the form. Overrides EntityForm:: |
|
MentionsTypeForm:: |
public | function |
This is the default entity object builder function. It is called before any
other submit handler to build the new entity object to be used by the
following submit handlers. At this point of the form workflow the entity is
validated and the form state… Overrides EntityForm:: |
|
MentionsTypeForm:: |
public | function | ||
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |