/**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     drupal_set_message($this->t('The static context %label has been removed.', ['%label' => $this->pageVariant->getStaticContext($this->staticContext)['label']]));
     $this->pageVariant->removeStaticContext($this->staticContext);
     $this->pageVariant->save();
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageVariantInterface $page_variant = NULL, $name = '')
 {
     $this->pageVariant = $page_variant;
     $this->staticContext = $this->pageVariant->getStaticContext($name);
     // Allow the condition to add to the form.
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#default_value' => isset($this->staticContext['label']) ? $this->staticContext['label'] : '', '#required' => TRUE];
     $form['machine_name'] = ['#type' => 'machine_name', '#maxlength' => 64, '#required' => TRUE, '#machine_name' => ['exists' => [$this, 'contextExists'], 'source' => ['label']], '#default_value' => $name];
     $form['entity_type'] = ['#type' => 'select', '#title' => $this->t('Entity type'), '#options' => $this->entityTypeRepository->getEntityTypeLabels(TRUE), '#limit_validation_errors' => array(array('entity_type')), '#submit' => ['::rebuildSubmit'], '#executes_submit_callback' => TRUE, '#ajax' => array('callback' => '::updateEntityType', 'wrapper' => 'add-static-context-wrapper', 'method' => 'replace')];
     $entity = NULL;
     if ($form_state->hasValue('entity_type')) {
         $entity_type = $form_state->getValue('entity_type');
         if ($this->staticContext['value']) {
             $entity = $this->entityRepository->loadEntityByUuid($entity_type, $this->staticContext['value']);
         }
     } elseif (!empty($this->staticContext['type'])) {
         list(, $entity_type) = explode(':', $this->staticContext['type']);
         $entity = $this->entityRepository->loadEntityByUuid($entity_type, $this->staticContext['value']);
     } elseif ($this->entityTypeManager->hasDefinition('node')) {
         $entity_type = 'node';
     } else {
         $entity_type = 'user';
     }
     $form['entity_type']['#default_value'] = $entity_type;
     $form['selection'] = ['#type' => 'entity_autocomplete', '#prefix' => '<div id="add-static-context-wrapper">', '#suffix' => '</div>', '#required' => TRUE, '#target_type' => $entity_type, '#default_value' => $entity, '#title' => $this->t('Select entity')];
     $form['actions'] = ['#type' => 'actions'];
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->submitButtonText(), '#button_type' => 'primary'];
     return $form;
 }
 /**
  * Route title callback.
  *
  * @param \Drupal\page_manager\PageVariantInterface $page_variant
  *   The page variant entity.
  * @param string $name
  *   The static context name.
  *
  * @return string
  *   The title for the static context edit form.
  */
 public function editStaticContextTitle(PageVariantInterface $page_variant, $name)
 {
     $static_context = $page_variant->getStaticContext($name);
     return $this->t('Edit @label static context', ['@label' => $static_context['label']]);
 }