Пример #1
0
 public function setUp()
 {
     $this->account = $this->prophesize(AccountInterface::class);
     $this->contextHandler = $this->prophesize(ContextHandlerInterface::class);
     $this->uuidGenerator = $this->prophesize(UuidInterface::class);
     $this->token = $this->prophesize(Token::class);
     $this->builderManager = $this->prophesize(DisplayBuilderManagerInterface::class);
     $this->layoutManager = $this->prophesize(LayoutPluginManagerInterface::class);
     $this->layout = $this->prophesize(LayoutInterface::class);
     $this->layoutManager->createInstance(Argument::type('string'), Argument::type('array'))->willReturn($this->layout->reveal());
     $this->variant = new PanelsDisplayVariant([], '', [], $this->contextHandler->reveal(), $this->account->reveal(), $this->uuidGenerator->reveal(), $this->token->reveal(), $this->builderManager->reveal(), $this->layoutManager->reveal());
 }
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     // Don't call VariantBase::buildConfigurationForm() on purpose, because it
     // adds a 'Label' field that we don't actually want to use - we store the
     // label on the page variant entity.
     //$form = parent::buildConfigurationForm($form, $form_state);
     // Allow to configure the page title, even when adding a new display.
     // Default to the page label in that case.
     $form['page_title'] = ['#type' => 'textfield', '#title' => $this->t('Page title'), '#description' => $this->t('Configure the page title that will be used for this display.'), '#default_value' => $this->configuration['page_title'] ?: ''];
     if (empty($this->configuration['builder'])) {
         $plugins = $this->builderManager->getDefinitions();
         $options = array();
         foreach ($plugins as $id => $plugin) {
             $options[$id] = $plugin['label'];
         }
         // Only allow the IPE if the storage information is set.
         if (!$this->getStorageType()) {
             unset($options['ipe']);
         }
         $form['builder'] = ['#title' => $this->t('Builder'), '#type' => 'select', '#options' => $options, '#default_value' => 'standard'];
     }
     $form['layout'] = ['#title' => $this->t('Layout'), '#type' => 'select', '#options' => Layout::getLayoutOptions(['group_by_category' => TRUE]), '#default_value' => $this->configuration['layout'] ?: NULL];
     if (!empty($this->configuration['layout'])) {
         $form['layout']['#ajax'] = ['callback' => [$this, 'layoutSettingsAjaxCallback'], 'wrapper' => 'layout-settings-wrapper', 'effect' => 'fade'];
         // If a layout is already selected, show the layout settings.
         $form['layout_settings_wrapper'] = ['#type' => 'fieldset', '#title' => $this->t('Layout settings'), '#prefix' => '<div id="layout-settings-wrapper">', '#suffix' => '</div>'];
         $form['layout_settings_wrapper']['layout_settings'] = [];
         // Process callback to configure #parents correctly on settings, since
         // we don't know where in the form hierarchy our settings appear.
         $form['#process'][] = [$this, 'layoutSettingsProcessCallback'];
     }
     return $form;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildConfigurationForm($form, $form_state);
     // Allow to configure the page title, even when adding a new display.
     // Default to the page label in that case.
     $form['page_title'] = ['#type' => 'textfield', '#title' => $this->t('Page title'), '#description' => $this->t('Configure the page title that will be used for this display.'), '#default_value' => $this->configuration['page_title'] ?: ''];
     if (empty($this->configuration['builder'])) {
         $plugins = $this->builderManager->getDefinitions();
         $options = array();
         foreach ($plugins as $id => $plugin) {
             $options[$id] = $plugin['label'];
         }
         $form['builder'] = ['#title' => $this->t('Builder'), '#type' => 'select', '#options' => $options, '#default_value' => 'standard'];
     }
     if (empty($this->configuration['layout'])) {
         $form['layout'] = ['#title' => $this->t('Layout'), '#type' => 'select', '#options' => Layout::getLayoutOptions(['group_by_category' => TRUE]), '#default_value' => NULL];
     } else {
         $form['layout'] = ['#type' => 'value', '#value' => $this->configuration['layout']];
         // If a layout is already selected, show the layout settings.
         $form['layout_settings_wrapper'] = ['#type' => 'fieldset', '#title' => $this->t('Layout settings')];
         $form['layout_settings_wrapper']['layout_settings'] = [];
         // Get settings form from layout plugin.
         $layout = $this->layoutManager->createInstance($this->configuration['layout'], $this->configuration['layout_settings'] ?: []);
         $form['layout_settings_wrapper']['layout_settings'] = $layout->buildConfigurationForm($form['layout_settings_wrapper']['layout_settings'], $form_state);
         // Process callback to configure #parents correctly on settings, since
         // we don't know where in the form hierarchy our settings appear.
         $form['#process'][] = [$this, 'layoutSettingsProcessCallback'];
     }
     return $form;
 }