public function BaseUpdateRunner::buildConfigurationForm in Scheduled Updates 8
Form constructor.
Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.
Parameters
array $form: An associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Return value
array The form structure.
Overrides PluginFormInterface::buildConfigurationForm
1 call to BaseUpdateRunner::buildConfigurationForm()
- IndependentUpdateRunner::buildConfigurationForm in src/
Plugin/ UpdateRunner/ IndependentUpdateRunner.php - Form constructor.
1 method overrides BaseUpdateRunner::buildConfigurationForm()
- IndependentUpdateRunner::buildConfigurationForm in src/
Plugin/ UpdateRunner/ IndependentUpdateRunner.php - Form constructor.
File
- src/
Plugin/ BaseUpdateRunner.php, line 389 - Contains \Drupal\scheduled_updates\Plugin\BaseUpdateRunner.
Class
Namespace
Drupal\scheduled_updates\PluginCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$settings = $form_state
->get('update_runner');
/** @var ScheduledUpdateType $type */
$type = $this
->getUpdateType($form_state);
$form['id'] = [
'#type' => 'value',
'#value' => $this
->getPluginId(),
];
$form['runner_advanced'] = [
'#type' => 'details',
'#title' => $this
->t('Advanced Runner Options'),
'#collasped' => TRUE,
'#weight' => 100,
];
$form['runner_advanced']['after_run'] = [
'#type' => 'select',
'#title' => $this
->t('After update behavior'),
'#description' => $this
->t('What should happen after updates are run?'),
'#required' => TRUE,
'#default_value' => !empty($settings['after_run']) ? $settings['after_run'] : UpdateRunnerInterface::AFTER_DELETE,
'#options' => [
UpdateRunnerInterface::AFTER_DELETE => $this
->t('Delete Updates'),
UpdateRunnerInterface::AFTER_ARCHIVE => $this
->t('Archive Updates'),
],
'#tree' => TRUE,
'#weight' => '0',
];
$form['runner_advanced']['invalid_update_behavior'] = [
'#type' => 'select',
'#title' => $this
->t('Invalid update behavior'),
'#description' => $this
->t('What should happen when an update is invalid?'),
'#required' => TRUE,
'#default_value' => !empty($settings['invalid_update_behavior']) ? $settings['invalid_update_behavior'] : UpdateRunnerInterface::INVALID_DELETE,
'#options' => [
UpdateRunnerInterface::INVALID_REQUEUE => $this
->t('Leave update in queue'),
UpdateRunnerInterface::INVALID_DELETE => $this
->t('Delete update'),
UpdateRunnerInterface::INVALID_ARCHIVE => $this
->t('Archive update'),
],
'#weight' => '20',
];
if ($type && $this->updateUtils
->supportsRevisionUpdates($type)) {
$revision_options = [];
if ($this->updateUtils
->supportsRevisionBundleDefault($type)) {
$revision_options = [
UpdateRunnerInterface::REVISIONS_BUNDLE_DEFAULT => $this
->t('Use bundle default.'),
];
}
$revision_options += [
UpdateRunnerInterface::REVISIONS_YES => $this
->t('Always Create New Revisions'),
UpdateRunnerInterface::REVISIONS_NO => $this
->t('Never Create New Revisions'),
];
$form['runner_advanced']['create_revisions'] = [
'#type' => 'select',
'#title' => $this
->t('Create New Revisions'),
'#description' => $this
->t('Should updates create new revisions of entities? Not all entity types support revisions.'),
'#required' => TRUE,
'#default_value' => !empty($settings['create_revisions']) ? $settings['create_revisions'] : UpdateRunnerInterface::REVISIONS_BUNDLE_DEFAULT,
'#options' => $revision_options,
'#weight' => '40',
];
}
$update_user_options = [
UpdateRunnerInterface::USER_UPDATE_RUNNER => $this
->t('The user who using running the updates. User #1 in cron.'),
UpdateRunnerInterface::USER_UPDATE_OWNER => $this
->t('The owner of the update.'),
];
if ($type && $this->updateUtils
->supportsOwner($type)) {
$update_user_options[UpdateRunnerInterface::USER_OWNER] = $this
->t('The owner of the entity to be updated');
}
if ($type && $this->updateUtils
->supportsRevisionOwner($type)) {
$update_user_options[UpdateRunnerInterface::USER_REVISION_OWNER] = $this
->t('The owner of the last revision.');
}
$form['runner_advanced']['update_user'] = [
'#type' => 'select',
'#title' => $this
->t('Run update as:'),
'#description' => $this
->t('Which user should the updates be run as?'),
'#required' => TRUE,
'#default_value' => !empty($settings['update_user']) ? $settings['update_user'] : UpdateRunnerInterface::USER_UPDATE_RUNNER,
'#options' => $update_user_options,
'#weight' => '60',
];
// Remove fieldset from parents.
foreach (Element::children($form['runner_advanced']) as $key) {
$form['runner_advanced'][$key]['#parents'] = [
'update_runner',
$key,
];
}
return $form;
}