/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $display_variant_id = NULL, $block_id = NULL)
 {
     $this->page = $page;
     $this->displayVariant = $this->page->getVariant($display_variant_id);
     $this->block = $this->displayVariant->getBlock($block_id);
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $display_variant_id = NULL, $condition_id = NULL)
 {
     $this->page = $page;
     $this->displayVariant = $this->page->getVariant($display_variant_id);
     $this->selectionCondition = $this->displayVariant->getSelectionCondition($condition_id);
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // The page might have been serialized, resulting in a new display variant
     // collection. Refresh the display variant and block objects.
     $this->displayVariant = $this->page->getVariant($form_state->get('display_variant_id'));
     $this->block = $this->displayVariant->getBlock($form_state->get('block_id'));
     $settings = (new FormState())->setValues($form_state->getValue('settings'));
     // Call the plugin validate handler.
     $this->block->validateConfigurationForm($form, $settings);
     // Update the original form values.
     $form_state->setValue('settings', $settings->getValues());
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state, PageInterface $page = NULL, $page_variant_id = NULL, $layout_region_id = NULL)
 {
     $this->page = $page;
     $this->pageVariant = $page->getVariant($page_variant_id);
     $this->pageVariant->init($this->page->getExecutable());
     $this->layoutRegion = $this->pageVariant->getLayoutRegion($layout_region_id);
     $form = parent::buildForm($form, $form_state);
     if ($this->getRequest()->isXmlHttpRequest()) {
         $form['actions']['submit']['#ajax'] = array('callback' => array($this, 'submitForm'));
     }
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, PageInterface $page = NULL, $page_variant_id = NULL)
 {
     // @todo: this is clearly not restful - but let's get this on the road
     switch ($request->getMethod()) {
         case 'PUT':
             $page_variant = $page->getVariant($page_variant_id);
             $page_variant->init($page->getExecutable());
             if (!$page_variant) {
                 throw BadRequestHttpException('Invalid page variant id provided');
             }
             $payload = $request->getContent();
             $data = json_decode($payload, TRUE);
             return $this->handlePut($page, $page_variant, $data);
             break;
         default:
             throw new BadRequestHttpException('Invalid HTTP method, currently only PUT supported');
     }
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state, PageInterface $page = NULL, $page_variant_id = NULL, $layout_region_id = NULL, $plugin_id = NULL)
 {
     $this->page = $page;
     $this->pageVariant = $page->getVariant($page_variant_id);
     $this->pageVariant->init($page->getExecutable());
     // Check for adding a (sub-)region to an existent region.
     if ($plugin_id) {
         $this->layoutRegion = $this->prepareLayoutRegion($plugin_id, $layout_region_id);
         $this->layoutRegion->parentLayoutRegion = $this->pageVariant->getLayoutRegion($layout_region_id);
     } else {
         $this->layoutRegion = $this->prepareLayoutRegion($layout_region_id);
     }
     // Allow the page variant to add to the form.
     $form['plugin'] = $this->layoutRegion->buildConfigurationForm(array(), $form_state);
     $form['plugin']['#tree'] = TRUE;
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->submitText(), '#button_type' => 'primary');
     if ($this->getRequest()->isXmlHttpRequest()) {
         $form['actions']['submit']['#ajax'] = array('callback' => array($this, 'submitForm'));
     }
     return $form;
 }
Esempio n. 7
0
 /**
  * Route title callback.
  *
  * @param \Drupal\page_manager\PageInterface $page
  *   The page entity.
  * @param string $display_variant_id
  *   The display variant ID.
  * @param string $condition_id
  *   The selection condition ID.
  *
  * @return string
  *   The title for the selection condition edit form.
  */
 public function editSelectionConditionTitle(PageInterface $page, $display_variant_id, $condition_id)
 {
     /** @var \Drupal\page_manager\Plugin\ConditionVariantInterface $display_variant */
     $display_variant = $page->getVariant($display_variant_id);
     $selection_condition = $display_variant->getSelectionCondition($condition_id);
     return $this->t('Edit %label selection condition', ['%label' => $selection_condition->getPluginDefinition()['label']]);
 }