abstract class AssignmentFormBase in Features 8.4
Same name and namespace in other branches
- 8.3 modules/features_ui/src/Form/AssignmentFormBase.php \Drupal\features_ui\Form\AssignmentFormBase
Configures the selected configuration assignment method for this site.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\features_ui\Form\AssignmentFormBase
Expanded class hierarchy of AssignmentFormBase
File
- modules/
features_ui/ src/ Form/ AssignmentFormBase.php, line 16
Namespace
Drupal\features_ui\FormView source
abstract class AssignmentFormBase extends FormBase {
/**
* The features manager.
*
* @var \Drupal\features\FeaturesManagerInterface
*/
protected $featuresManager;
/**
* The package assigner.
*
* @var \Drupal\features\FeaturesAssignerInterface
*/
protected $assigner;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The current bundle.
*
* @var \Drupal\features\FeaturesBundleInterface
*/
protected $currentBundle;
/**
* Constructs a AssignmentBaseForm object.
*
* @param \Drupal\features\FeaturesManagerInterface $features_manager
* The features manager.
* @param \Drupal\features\FeaturesAssignerInterface $assigner
* The assigner.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(FeaturesManagerInterface $features_manager, FeaturesAssignerInterface $assigner, EntityTypeManagerInterface $entity_type_manager) {
$this->featuresManager = $features_manager;
$this->assigner = $assigner;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('features.manager'), $container
->get('features_assigner'), $container
->get('entity_type.manager'));
}
/**
* Adds configuration types checkboxes.
*/
protected function setConfigTypeSelect(&$form, $defaults, $type, $bundles_only = FALSE, $description = '') {
$options = $this->featuresManager
->listConfigTypes($bundles_only);
if (!isset($form['types'])) {
$form['types'] = [
'#type' => 'container',
'#tree' => TRUE,
];
}
$form['types']['config'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Configuration types'),
'#description' => !empty($description) ? $description : $this
->t('Select types of configuration that should be considered @type types.', [
'@type' => $type,
]),
'#options' => $options,
'#default_value' => $defaults,
];
}
/**
* Adds content entity types checkboxes.
*/
protected function setContentTypeSelect(&$form, $defaults, $type, $exclude_has_config_bundles = TRUE) {
$entity_types = $this->entityTypeManager
->getDefinitions();
$has_config_bundle = [];
foreach ($entity_types as $definition) {
if ($entity_type_id = $definition
->getBundleOf()) {
$has_config_bundle[] = $entity_type_id;
}
}
$options = [];
foreach ($entity_types as $entity_type_id => $entity_type) {
if (!$entity_type instanceof ContentEntityTypeInterface) {
continue;
}
if ($exclude_has_config_bundles && in_array($entity_type_id, $has_config_bundle)) {
continue;
}
$options[$entity_type_id] = $entity_type
->getLabel() ?: $entity_type_id;
}
// Sort the entity types by label.
uasort($options, 'strnatcasecmp');
if (!isset($form['types'])) {
$form['types'] = [
'#type' => 'container',
'#tree' => TRUE,
];
}
$form['types']['content'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Content entity types'),
'#description' => $this
->t('Select content entity types that should be considered @type types.', [
'@type' => $type,
]),
'#options' => $options,
'#default_value' => $defaults,
];
}
/**
* Adds a "Save settings" submit action.
*/
protected function setActions(&$form, $method_id = NULL) {
$assignment_info = $this->assigner
->getAssignmentMethods();
if (isset($method_id) && isset($assignment_info[$method_id])) {
$method = $assignment_info[$method_id];
$form['help_text'] = [
'#markup' => $method['description'],
'#prefix' => '<p class="messages messages--status">',
'#suffix' => '</p>',
'#weight' => -99,
];
}
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this
->t('Save settings'),
];
$form['#attributes']['class'][] = 'features-assignment-settings-form';
$form['#attached'] = [
'library' => [
'features_ui/drupal.features_ui.admin',
],
];
}
/**
* Redirects back to the Bundle config form.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
protected function setRedirect(FormStateInterface $form_state) {
$form_state
->setRedirect('features.assignment', [
'bundle_name' => $this->currentBundle
->getMachineName(),
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssignmentFormBase:: |
protected | property | The package assigner. | |
AssignmentFormBase:: |
protected | property | The current bundle. | |
AssignmentFormBase:: |
protected | property | The entity type manager. | |
AssignmentFormBase:: |
protected | property | The features manager. | |
AssignmentFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
1 |
AssignmentFormBase:: |
protected | function | Adds a "Save settings" submit action. | |
AssignmentFormBase:: |
protected | function | Adds configuration types checkboxes. | |
AssignmentFormBase:: |
protected | function | Adds content entity types checkboxes. | |
AssignmentFormBase:: |
protected | function | Redirects back to the Bundle config form. | |
AssignmentFormBase:: |
public | function | Constructs a AssignmentBaseForm object. | 1 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
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. Overrides UrlGeneratorTrait:: |
|
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:: |
62 |
FormInterface:: |
public | function | Form constructor. | 179 |
FormInterface:: |
public | function | Returns a unique string identifying the form. | 236 |
FormInterface:: |
public | function | Form submission handler. | 192 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
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. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
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. | 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:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |