public function SmartQueue::buildConfigurationForm in Entityqueue 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 EntityQueueHandlerBase::buildConfigurationForm
File
- modules/
entityqueue_smartqueue/ src/ Plugin/ EntityQueueHandler/ SmartQueue.php, line 89
Class
- SmartQueue
- Plugin annotation @EntityQueueHandler( id = "smartqueue", title = @Translation("Smart queue"), description = @Translation("Provides automated subqueues for each entity of a given type."), )
Namespace
Drupal\entityqueue_smartqueue\Plugin\EntityQueueHandlerCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['entity_type'] = [
'#type' => 'select',
'#title' => $this
->t('Entity type'),
'#description' => $this
->t('The entity type for which subqueues will be created automatically.'),
'#options' => $this->entityTypeRepository
->getEntityTypeLabels(TRUE),
'#default_value' => $this->configuration['entity_type'],
'#empty_option' => $this
->t('- Select -'),
'#required' => TRUE,
'#disabled' => !$this->queue
->isNew(),
'#ajax' => [
'wrapper' => 'smartqueue-bundle-wrapper',
'callback' => [
get_class($this),
'smartqueueSettingsAjax',
],
'method' => 'replace',
],
];
$form_state_values = $form_state
->getCompleteFormState()
->getValues();
$entity_type_id = isset($form_state_values['handler_settings_wrapper']) ? $form_state_values['handler_settings_wrapper']['handler_settings']['entity_type'] : $this->configuration['entity_type'];
if ($bundle_options = $this
->getBundleOptions($entity_type_id)) {
$form['bundles'] = [
'#type' => 'checkboxes',
'#title' => $this->entityTypeManager
->getDefinition($entity_type_id)
->getBundleLabel(),
'#options' => $bundle_options,
'#default_value' => (array) $this->configuration['bundles'],
'#required' => TRUE,
'#size' => 6,
'#multiple' => TRUE,
'#prefix' => '<div id="smartqueue-bundle-wrapper">',
'#suffix' => '</div>',
];
}
else {
$form['bundles'] = [
'#type' => 'value',
'#value' => [
$entity_type_id => $entity_type_id,
],
'#prefix' => '<div id="smartqueue-bundle-wrapper">',
'#suffix' => '</div>',
];
}
return $form;
}