AddVariantSelectionForm.php in Page Manager 8.4
File
page_manager_ui/src/Form/AddVariantSelectionForm.php
View source
<?php
namespace Drupal\page_manager_ui\Form;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\OpenModalDialogCommand;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\ctools\Form\ManageConditions;
class AddVariantSelectionForm extends ManageConditions {
public function getFormId() {
return 'page_manager_access_form';
}
protected function getConditionClass() {
return AddVariantSelectionConfigure::class;
}
protected function getTempstoreId() {
return 'page_manager.page_variant';
}
protected function getOperationsRouteInfo($cached_values, $machine_name, $row) {
$page_variant = $cached_values['page_variant'];
return [
'entity.page_variant.add_step_form.condition',
[
'page' => $page_variant
->getPage()
->id(),
'machine_name' => $machine_name,
'condition' => $row,
],
];
}
protected function getConditions($cached_values) {
$page_variant = $cached_values['page_variant'];
return $page_variant
->get('selection_criteria');
}
protected function getContexts($cached_values) {
$page_variant = $cached_values['page_variant'];
return $page_variant
->getContexts();
}
protected function getAddRoute($cached_values) {
return 'entity.page_variant.add_step_form.condition.add';
}
public function add(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
$page_variant = $cached_values['page_variant'];
$condition = $form_state
->getValue('conditions');
$content = \Drupal::formBuilder()
->getForm($this
->getConditionClass(), $condition, $this
->getTempstoreId(), $this->machine_name, $page_variant
->id());
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
list(, $route_parameters) = $this
->getOperationsRouteInfo($cached_values, $this->machine_name, $form_state
->getValue('conditions'));
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = Url::fromRoute($this
->getAddRoute($cached_values), $route_parameters, [
'query' => [
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
],
])
->toString();
$response = new AjaxResponse();
$response
->addCommand(new OpenModalDialogCommand($this
->t('Configure Required Context'), $content, [
'width' => '700',
]));
return $response;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$triggering_element = $form_state
->getTriggeringElement();
if ($triggering_element['#value']
->getUntranslatedString() != 'Add Condition') {
return;
}
parent::submitForm($form, $form_state);
}
}