class ScheduledUpdateTypeAddAsFieldForm in Scheduled Updates 8
Class ScheduledUpdateTypeAddAsFieldForm.
@package Drupal\scheduled_updates\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
- class \Drupal\scheduled_updates\Form\ScheduledUpdateTypeBaseForm uses ClassUtilsTrait, FieldUtilsTrait
- class \Drupal\scheduled_updates\Form\ScheduledUpdateTypeAddAsFieldForm
- class \Drupal\scheduled_updates\Form\ScheduledUpdateTypeBaseForm uses ClassUtilsTrait, FieldUtilsTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
Expanded class hierarchy of ScheduledUpdateTypeAddAsFieldForm
File
- src/
Form/ ScheduledUpdateTypeAddAsFieldForm.php, line 20 - Contains \Drupal\scheduled_updates\Form\ScheduledUpdateTypeAddAsFieldForm.
Namespace
Drupal\scheduled_updates\FormView source
class ScheduledUpdateTypeAddAsFieldForm extends ScheduledUpdateTypeBaseForm {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['update_entity_type'] = [
'#type' => 'value',
'#value' => $this
->getCurrentEntityType($form_state),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity_type = $this
->getCurrentEntityType($form_state);
$values = $form_state
->cleanValues()
->getValues();
$bundle = $form_state
->get('target_bundle');
$clone_field = $values['clone_field'];
$clone_field_id = NULL;
// When adding a field we don't expose the Label and Id of Bundle itself.
$type_label = $this
->entityLabel($entity_type) . ' - ' . $this
->getFieldLabel($entity_type, $bundle, $clone_field);
$this->entity
->set('label', $type_label);
$this->entity
->set('id', $this
->createNewUpdateTypeName($entity_type, $clone_field));
parent::doSave($form, $form_state);
$this
->cloneSingleField($entity_type, $clone_field, $form_state, $bundle);
$bundle_type = $this->entityTypeManager
->getDefinition($entity_type)
->getBundleEntityType();
$form_state
->setRedirectUrl(Url::fromRoute("entity.entity_form_display.{$entity_type}.default", array(
$bundle_type => $form_state
->get('target_bundle'),
)));
}
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $mode = 'independent', $bundle = '') {
$form_state
->set('target_entity_type_id', $entity_type_id);
$form_state
->set('target_bundle', $bundle);
$this->entity
->setUpdateEntityType($entity_type_id);
return parent::buildForm($form, $form_state);
}
public function afterBuild(array $form, FormStateInterface $form_state) {
$form = parent::afterBuild($form, $form_state);
$trigger = $form_state
->getTriggeringElement();
if ($trigger['#name'] == 'clone_field' && ($clone_field = $form_state
->getValue('clone_field'))) {
$new_field_element =& $form['type_dependent_elements']['reference_settings']['new_field'];
$selected_field_label = $form['type_dependent_elements']['clone_field']['#options'][$clone_field];
$new_field_element['label']['#value'] = $selected_field_label . ' ' . $this
->t('Update');
$new_field_element['field_name']['#value'] = '';
}
return $form;
}
/**
* Create an update type name programmatically.
*
* @param $entity_type
* @param $clone_field
*
* @return string
*/
protected function createNewUpdateTypeName($entity_type, $clone_field) {
$name = $entity_type . '__' . $clone_field;
$suffix = 0;
$new_name = $name;
while (ScheduledUpdateType::load($new_name)) {
$suffix++;
$new_name = $name . '_' . $suffix;
}
return $new_name;
}
/**
* {@inheritdoc}
*
* Override to only return runners that support embedded updates.
*/
protected function getSupportedRunnerDefinitions() {
$definitions = parent::getSupportedRunnerDefinitions();
$supported_definitions = [];
foreach ($definitions as $id => $definition) {
if (in_array('embedded', $definition['update_types'])) {
$supported_definitions[$id] = $definition;
}
}
return $supported_definitions;
}
/**
*{@inheritdoc}
*/
protected function getDefaultBundle($field_selected, FormStateInterface $form_state) {
return $form_state
->get('target_bundle');
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClassUtilsTrait:: |
protected | function | ||
ClassUtilsTrait:: |
protected | function | Determines if the class for an entity type definition implements and interface. | |
ClassUtilsTrait:: |
protected | function | ||
ClassUtilsTrait:: |
protected | function | ||
ClassUtilsTrait:: |
protected | function | Get the entity owner if applicable. | |
ClassUtilsTrait:: |
protected | function | Get the revision owner for an ContentEntity. | |
ClassUtilsTrait:: |
protected | function | Determines if an object or class name implements any interfaces in a list. | |
ClassUtilsTrait:: |
protected | function | Get class names of interfaces that support revision ownership. | |
ClassUtilsTrait:: |
protected | function | ||
ClassUtilsTrait:: |
protected | function | ||
ClassUtilsTrait:: |
public | function | ||
ClassUtilsTrait:: |
protected | function | ||
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 | |
EntityForm:: |
protected | property | The entity type manager. | 3 |
EntityForm:: |
protected | property | The name of the current operation. | |
EntityForm:: |
private | property | The entity manager. | |
EntityForm:: |
protected | function | Returns an array of supported actions for the current entity form. | 29 |
EntityForm:: |
protected | function | Returns the action form element for the current entity form. | |
EntityForm:: |
public | function |
Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface:: |
2 |
EntityForm:: |
protected | function | Copies top-level form values to entity properties | 7 |
EntityForm:: |
public | function |
Returns a string identifying the base form. Overrides BaseFormIdInterface:: |
5 |
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:: |
1 |
EntityForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
10 |
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 |
Sets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity manager for this form. 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:: |
|
EntityForm:: |
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 FormInterface:: |
17 |
EntityForm:: |
public | function | ||
EntityForm:: |
public | function | ||
FieldUtilsTrait:: |
protected | function | ||
FieldUtilsTrait:: |
protected | function | Return all fields that can be used as destinations fields. | |
FieldUtilsTrait:: |
protected | function | ||
FieldUtilsTrait:: |
protected | function | ||
FieldUtilsTrait:: |
public | function | Get field definition on bundle. | |
FieldUtilsTrait:: |
protected | function | ||
FieldUtilsTrait:: |
protected | function | Utility Function to load a single field definition. | |
FieldUtilsTrait:: |
protected | function | Get Fields that can used as a destination field for this type. | |
FieldUtilsTrait:: |
protected | function | ||
FieldUtilsTrait:: |
protected | function | Check if a field on the entity type to update is a possible destination field. | |
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. | |
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. | |
ScheduledUpdateTypeAddAsFieldForm:: |
public | function |
Form element #after_build callback: Updates the entity with submitted data. Overrides EntityForm:: |
|
ScheduledUpdateTypeAddAsFieldForm:: |
public | function |
Form constructor. Overrides EntityForm:: |
|
ScheduledUpdateTypeAddAsFieldForm:: |
protected | function | Create an update type name programmatically. | |
ScheduledUpdateTypeAddAsFieldForm:: |
public | function |
Gets the actual form array to be built. Overrides ScheduledUpdateTypeBaseForm:: |
|
ScheduledUpdateTypeAddAsFieldForm:: |
protected | function |
Determine the default that should be used to create default value elements. Overrides ScheduledUpdateTypeBaseForm:: |
|
ScheduledUpdateTypeAddAsFieldForm:: |
protected | function |
Override to only return runners that support embedded updates. Overrides ScheduledUpdateTypeBaseForm:: |
|
ScheduledUpdateTypeAddAsFieldForm:: |
public | function |
Form submission handler for the 'save' action. Overrides EntityForm:: |
|
ScheduledUpdateTypeBaseForm:: |
protected | property |
@var ScheduledUpdateType Overrides EntityForm:: |
|
ScheduledUpdateTypeBaseForm:: |
protected | property | ||
ScheduledUpdateTypeBaseForm:: |
protected | property | ||
ScheduledUpdateTypeBaseForm:: |
protected | property |
Overrides EntityForm:: |
|
ScheduledUpdateTypeBaseForm:: |
protected | property | ||
ScheduledUpdateTypeBaseForm:: |
protected | property | ||
ScheduledUpdateTypeBaseForm:: |
protected | function | Clone a single field from the settings on type add form. | |
ScheduledUpdateTypeBaseForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ScheduledUpdateTypeBaseForm:: |
protected | function | Create an option to select one field to clone on type add form. | 1 |
ScheduledUpdateTypeBaseForm:: |
protected | function | Create the default value elements for a field. | |
ScheduledUpdateTypeBaseForm:: |
protected | function | Create options for create a new entity reference field. | |
ScheduledUpdateTypeBaseForm:: |
protected | function | Create form elements for runner selection and options. | |
ScheduledUpdateTypeBaseForm:: |
protected | function | Create an instance of the Runner plugin to be used with this Update Type. | |
ScheduledUpdateTypeBaseForm:: |
public | function | Save the entity on submit. | |
ScheduledUpdateTypeBaseForm:: |
protected | function | Get existing entity reference field on target entity type that reference scheduled updates. | |
ScheduledUpdateTypeBaseForm:: |
public | function |
Overrides FieldUtilsTrait:: |
|
ScheduledUpdateTypeBaseForm:: |
public | function | Checks if a field machine name is taken. | |
ScheduledUpdateTypeBaseForm:: |
protected | function | Get the current entity type to be updated for update type. | |
ScheduledUpdateTypeBaseForm:: |
protected | function | Get the widget that should used for the default value. | |
ScheduledUpdateTypeBaseForm:: |
private | function | Determine if we should try to make a default value widget. | |
ScheduledUpdateTypeBaseForm:: |
protected | function | ||
ScheduledUpdateTypeBaseForm:: |
protected | function | Setup entity reference field for this update type on add. | |
ScheduledUpdateTypeBaseForm:: |
protected | function | ||
ScheduledUpdateTypeBaseForm:: |
public | function | Ajax Form call back for Update Runner Fieldset. | |
ScheduledUpdateTypeBaseForm:: |
public | function | Ajax Form call back for Create Reference Fieldset. | |
ScheduledUpdateTypeBaseForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
1 |
ScheduledUpdateTypeBaseForm:: |
public | function | Constructs a ScheduledUpdateTypeForm 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:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |