コード例 #1
0
ファイル: PageFormBase.php プロジェクト: neeravbm/unify-d8
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#description' => $this->t('The label for this page.'), '#default_value' => $this->entity->label(), '#required' => TRUE, '#maxlength' => '255'];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $this->entity->id(), '#disabled' => !$this->entity->isNew(), '#maxlength' => 64, '#required' => TRUE, '#machine_name' => ['exists' => [$this, 'exists']]];
     $form['path'] = ['#type' => 'textfield', '#title' => $this->t('Path'), '#maxlength' => 255, '#default_value' => $this->entity->getPath(), '#required' => TRUE, '#element_validate' => [[$this, 'validatePath']]];
     return parent::form($form, $form_state);
 }
コード例 #2
0
 /**
  * Enables or disables a Page.
  *
  * @param \Drupal\page_manager\PageInterface $page
  *   The page entity.
  * @param string $op
  *   The operation to perform, usually 'enable' or 'disable'.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirect back to the pages list page.
  */
 public function performPageOperation(PageInterface $page, $op)
 {
     $page->{$op}()->save();
     if ($op == 'enable') {
         drupal_set_message($this->t('The %label page has been enabled.', ['%label' => $page->label()]));
     } elseif ($op == 'disable') {
         drupal_set_message($this->t('The %label page has been disabled.', ['%label' => $page->label()]));
     }
     return $this->redirect('entity.page.collection');
 }