コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Return early if there are any errors.
     if ($form_state->hasAnyErrors()) {
         return $form;
     }
     $panels_display = $this->panelsDisplay;
     // Submit the layout form.
     $layout_form_state = (new FormState())->setValues($form_state->getValue('settings', []));
     $this->layout->submitConfigurationForm($form, $layout_form_state);
     $layout_config = $this->layout->getConfiguration();
     // Shift our blocks to the first available region. The IPE can control
     // re-assigning blocks in a smarter way.
     $region_definitions = $this->layout->getRegionDefinitions();
     $first_region = reset(array_keys($region_definitions));
     // For each block, set the region to match the new layout.
     foreach ($panels_display->getRegionAssignments() as $region => $region_assignment) {
         /** @var \Drupal\Core\Block\BlockPluginInterface $block */
         foreach ($region_assignment as $block_id => $block) {
             $block_config = $block->getConfiguration();
             // If the new layout does not have a region with the same name, use the
             // first available region.
             if (!isset($region_definitions[$block_config['region']])) {
                 $block_config['region'] = $first_region;
                 $panels_display->updateBlock($block_id, $block_config);
             }
         }
     }
     // Have our panels display use the new layout.
     $this->panelsDisplay->setLayout($this->layout, $layout_config);
     // Update tempstore.
     $this->tempStore->set($panels_display->id(), $panels_display->getConfiguration());
     $region_data = [];
     $region_content = [];
     // Compile region content and metadata.
     $regions = $panels_display->getRegionAssignments();
     foreach ($regions as $id => $label) {
         // Wrap the region with a class/data attribute that our app can use.
         $region_name = Html::getClass("block-region-{$id}");
         $region_content[$id] = ['#prefix' => '<div class="' . $region_name . '" data-region-name="' . $id . '">', '#suffix' => '</div>'];
         // Format region metadata.
         $region_data[] = ['name' => $id, 'label' => $label];
     }
     $build = $panels_display->getLayout()->build($region_content);
     $form['build'] = $build;
     $data = ['id' => $this->layout->getPluginId(), 'label' => $layout_config['label'], 'current' => TRUE, 'html' => $this->renderer->render($build), 'regions' => $region_data];
     // Add Block metadata and HTML as a drupalSetting.
     $form['#attached']['drupalSettings']['panels_ipe']['updated_layout'] = $data;
     return $form;
 }
コード例 #2
0
ファイル: DsLayout.php プロジェクト: darrylri/protovbmwmo
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildConfigurationForm($form, $form_state);
     $configuration = $this->getConfiguration();
     $regions = $this->getRegionDefinitions();
     // Add wrappers
     $wrapper_options = array('div' => 'Div', 'span' => 'Span', 'section' => 'Section', 'article' => 'Article', 'header' => 'Header', 'footer' => 'Footer', 'aside' => 'Aside', 'figure' => 'Figure');
     $form['region_wrapper'] = array('#group' => 'additional_settings', '#type' => 'details', '#title' => t('Custom wrappers'), '#description' => t('Choose a wrapper. All Display Suite layouts support this option.'), '#tree' => TRUE);
     foreach ($regions as $region_name => $region_definition) {
         $form['region_wrapper'][$region_name] = array('#type' => 'select', '#options' => $wrapper_options, '#title' => t('Wrapper for @region', array('@region' => $region_definition['label'])), '#default_value' => !empty($configuration['wrappers'][$region_name]) ? $configuration['wrappers'][$region_name] : 'div');
     }
     $form['region_wrapper']['outer_wrapper'] = array('#type' => 'select', '#options' => $wrapper_options, '#title' => t('Outer wrapper'), '#default_value' => $configuration['outer_wrapper'], '#weight' => 10);
     $form['region_wrapper']['attributes'] = array('#type' => 'textfield', '#title' => t('Layout attributes'), '#description' => 'E.g. role|navigation,data-something|some value', '#default_value' => $configuration['attributes'], '#weight' => 11);
     $form['region_wrapper']['link_attribute'] = array('#type' => 'select', '#options' => array('' => t('No link'), 'content' => t('Link to content'), 'custom' => t('Custom'), 'tokens' => t('Tokens')), '#title' => t('Add link'), '#description' => t('This will add an onclick attribute on the layout wrapper.'), '#default_value' => $configuration['link_attribute'], '#weight' => 12);
     $form['region_wrapper']['link_custom'] = array('#type' => 'textfield', '#title' => t('Custom link'), '#description' => t('You may use tokens for this link if you selected tokens.'), '#default_value' => $configuration['link_custom'], '#weight' => 13, '#states' => array('visible' => array(array(':input[name="region_wrapper[link_attribute]"]' => array(array("value" => "tokens"), array("value" => "custom"))))));
     if (\Drupal::moduleHandler()->moduleExists('token')) {
         $form['region_wrapper']['tokens'] = array('#title' => t('Tokens'), '#type' => 'container', '#weight' => 14, '#states' => array('visible' => array(':input[name="region_wrapper[link_attribute]"]' => array("value" => "tokens"))));
         $form['region_wrapper']['tokens']['help'] = array('#theme' => 'token_tree', '#token_types' => 'all', '#global_types' => FALSE, '#dialog' => TRUE);
     }
     // Add extra classes for the regions to have more control while theming.
     $form['ds_classes'] = array('#group' => 'additional_settings', '#type' => 'details', '#title' => t('Custom classes'), '#tree' => TRUE, '#collapsible' => TRUE, '#collapsed' => TRUE);
     $classes_access = \Drupal::currentUser()->hasPermission('admin_classes');
     $classes = Ds::getClasses();
     if (!empty($classes)) {
         $form['ds_classes']['layout_class'] = array('#type' => 'select', '#multiple' => TRUE, '#options' => $classes, '#title' => t('Class for layout'), '#default_value' => !empty($configuration['classes']['layout_class']) ? $configuration['classes']['layout_class'] : []);
         foreach ($regions as $region_name => $region_definition) {
             $form['ds_classes'][$region_name] = array('#type' => 'select', '#multiple' => TRUE, '#options' => $classes, '#title' => t('Class for @region', array('@region' => $region_definition['label'])), '#default_value' => isset($configuration['classes'][$region_name]) ? $configuration['classes'][$region_name] : []);
         }
         if ($classes_access) {
             $url = Url::fromRoute('ds.classes');
             $destination = \Drupal::destination()->getAsArray();
             $url->setOption('query', $destination);
             $form['ds_classes']['info'] = array('#markup' => \Drupal::l(t('Manage region and field CSS classes'), $url));
         }
     } else {
         if ($classes_access) {
             $url = Url::fromRoute('ds.classes');
             $destination = \Drupal::destination()->getAsArray();
             $url->setOption('query', $destination);
             $form['ds_classes']['info'] = array('#markup' => '<p>' . t('You have not defined any CSS classes which can be used on regions.') . '</p><p>' . \Drupal::l(t('Manage region and field CSS classes'), $url) . '</p>');
         } else {
             $form['ds_classes']['#access'] = FALSE;
         }
     }
     return $form;
 }
コード例 #3
0
 /**
  * @inheritDoc
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitConfigurationForm($form, $form_state);
     $this->configuration['setting_1'] = $form_state->getValue('setting_1');
 }