/**
  * {@inheritdoc}
  */
 public function alterForm(&$form)
 {
     $config = $this->getConfiguration();
     $form['lb'] = array('#type' => 'textfield', '#title' => t('Label'), '#size' => '10', '#default_value' => $config['lb']);
     $form['lb-col'] = array('#type' => 'checkbox', '#title' => t('Show label colon'), '#default_value' => $config['lb-col'], '#attributes' => array('class' => array('colon-checkbox')));
     $field_classes = Ds::getClasses('field');
     if (!empty($field_classes)) {
         $form['classes'] = array('#type' => 'select', '#multiple' => TRUE, '#options' => $field_classes, '#title' => t('Choose additional CSS classes for the field'), '#default_value' => $config['classes'], '#prefix' => '<div class="field-classes">', '#suffix' => '</div>');
     } else {
         $form['classes'] = array('#type' => 'value', '#value' => array());
     }
 }
Example #2
0
 /**
  * Returns an array of ds extras permissions.
  *
  * @return array
  */
 public function extrasPermissions()
 {
     $permissions = [];
     if (\Drupal::config('ds_extras.settings')->get('field_permissions')) {
         $entities = $this->entityTypeManager->getDefinitions();
         foreach ($entities as $entity_type => $info) {
             // @todo do this on all fields ?
             // @todo hide switch field if enabled
             $fields = Ds::getFields($entity_type);
             foreach ($fields as $key => $finfo) {
                 $permissions['view ' . $key . ' on ' . $entity_type] = array('title' => t('View @field on @entity_type', array('@field' => $finfo['title'], '@entity_type' => $info->getLabel())));
             }
         }
     }
     return $permissions;
 }
Example #3
0
 /**
  * {@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;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function alterForm(&$form) {
   // Field classes.
   $config = $this->getConfiguration();
   $field_classes = Ds::getClasses('field');
   if (!empty($field_classes)) {
     $form['classes'] = array(
       '#type' => 'select',
       '#multiple' => TRUE,
       '#options' => $field_classes,
       '#title' => t('Choose additional CSS classes for the field'),
       '#default_value' => $config['classes'],
       '#prefix' => '<div class="field-classes">',
       '#suffix' => '</div>',
     );
   }
   else {
     $form['classes'] = array(
       '#type' => 'value',
       '#value' => array(''),
     );
   }
   parent::alterForm($form);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '', $display_mode = '', $new_layout = '')
 {
     $old_layout = NULL;
     $all_layouts = Ds::getLayouts();
     if (!empty($entity_type) && !empty($bundle) && !empty($display_mode)) {
         $display = entity_get_display($entity_type, $bundle, $display_mode);
         $old_layout = $display->getThirdPartySettings('ds');
     }
     if ($old_layout && isset($all_layouts[$new_layout])) {
         $new_layout_key = $new_layout;
         $new_layout = $all_layouts[$new_layout];
         $old_layout_info = $all_layouts[$old_layout['layout']['id']];
         $form['#entity_type'] = $entity_type;
         $form['#entity_bundle'] = $bundle;
         $form['#mode'] = $display_mode;
         $form['#old_layout'] = $old_layout;
         $form['#old_layout_info'] = $old_layout_info;
         $form['#new_layout'] = $new_layout;
         $form['#new_layout_key'] = $new_layout_key;
         $form['info'] = array('#markup' => t('You are changing from @old to @new layout for @bundle in @view_mode view mode.', array('@old' => $old_layout_info['label'], '@new' => $new_layout['label'], '@bundle' => $bundle, '@view_mode' => $display_mode)), '#prefix' => "<div class='change-ds-layout-info'>", '#suffix' => "</div>");
         // Old region options.
         $regions = array();
         foreach ($old_layout_info['regions'] as $key => $info) {
             $regions[$key] = $info['label'];
         }
         // Let other modules alter the regions.
         // For old regions.
         $context = array('entity_type' => $entity_type, 'bundle' => $bundle, 'view_mode' => $display_mode);
         $region_info = array('region_options' => $regions);
         \Drupal::moduleHandler()->alter('ds_layout_region', $context, $region_info);
         $regions = $region_info['region_options'];
         $form['#old_layout_info']['layout']['regions'] = $regions;
         // For new regions.
         $new_regions = array();
         foreach ($new_layout['regions'] as $key => $info) {
             $new_regions[$key] = $info['label'];
         }
         $region_info = array('region_options' => $new_regions);
         \Drupal::moduleHandler()->alter('ds_layout_region', $context, $region_info);
         $new_layout['regions'] = $region_info['region_options'];
         $form['#new_layout']['regions'] = $new_layout['regions'];
         // Display the region options
         $selectable_regions = array('' => t('- None -')) + $new_layout['regions'];
         $form['regions_pre']['#markup'] = '<div class="ds-layout-regions">';
         foreach ($regions as $region => $region_title) {
             $form['region_' . $region] = array('#type' => 'container');
             $form['region_' . $region]['ds_label_' . $region] = array('#markup' => 'Fields in <span class="change-ds-layout-old-region"> ' . $region_title . '</span> go into');
             $form['region_' . $region]['ds_' . $region] = array('#type' => 'select', '#options' => $layout_options = $selectable_regions, '#default_value' => $region);
         }
         $form['regions_post']['#markup'] = '</div>';
         // Show previews from old and new layouts
         $form['preview'] = array('#type' => 'container', '#prefix' => '<div class="ds-layout-preview">', '#suffix' => '</div>');
         $fallback_image = drupal_get_path('module', 'ds') . '/images/preview.png';
         $old_image = isset($old_layout_info['icon']) && !empty($old_layout_info['icon']) ? $old_layout_info['icon'] : $fallback_image;
         $new_image = isset($new_layout['icon']) && !empty($new_layout['icon']) ? $new_layout['icon'] : $fallback_image;
         $arrow = drupal_get_path('module', 'ds') . '/images/arrow.png';
         $form['preview']['old_layout'] = array('#markup' => '<div class="ds-layout-preview-image"><img src="' . base_path() . $old_image . '"/></div>');
         $form['preview']['arrow'] = array('#markup' => '<div class="ds-layout-preview-arrow"><img src="' . base_path() . $arrow . '"/></div>');
         $form['preview']['new_layout'] = array('#markup' => '<div class="ds-layout-preview-image"><img src="' . base_path() . $new_image . '"/></div>');
         $form['#attached']['library'][] = 'ds/admin';
         // Submit button
         $form['actions'] = array('#type' => 'actions');
         $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#prefix' => '<div class="ds-layout-change-save">', '#suffix' => '</div>');
     } else {
         $form['nothing'] = array('#markup' => t('No valid configuration found.'));
     }
     return $form;
 }
Example #6
0
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config('ds.settings');

    $form['additional_settings'] = array(
      '#type' => 'vertical_tabs',
      '#attached' => array(
        'library' => array('ds/admin'),
      ),
    );

    $form['fs1'] = array(
      '#type' => 'details',
      '#title' => t('Field Templates'),
      '#group' => 'additional_settings',
      '#tree' => TRUE,
      '#collapsed' => FALSE,
    );

    $form['fs1']['field_template'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable Field Templates'),
      '#description' => t('Customize the labels and the HTML output of your fields.'),
      '#default_value' => $config->get('field_template'),
    );

    $theme_functions = Ds::getFieldLayoutOptions();
    $url = new Url('ds.classes');
    $form['fs1']['ft-default'] = array(
      '#type' => 'select',
      '#title' => t('Default Field Template'),
      '#options' => $theme_functions,
      '#default_value' => $config->get('ft-default'),
      '#description' => t('Default will output the field as defined in Drupal Core.<br />Reset will strip all HTML.<br />Minimal adds a simple wrapper around the field.<br/>There is also an Expert Field Template that gives full control over the HTML, but can only be set per field.<br /><br />You can override this setting per field on the "Manage display" screens or when creating fields on the instance level.<br /><br /><strong>Template suggestions</strong><br />You can create .html.twig files as well for these field theme functions, e.g. field--reset.html.twig, field--minimal.html.twig<br /><br /><label>CSS classes</label>You can add custom CSS classes on the <a href=":url">classes form</a>. These classes can be added to fields using the Default Field Template.<br /><br /><label>Advanced</label>You can create your own custom field templates which need to be defined with hook_ds_field_theme_functions_info(). See ds.api.php for an example.', array(':url' => $url->toString())),
      '#states' => array(
        'visible' => array(
          'input[name="fs1[field_template]"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['fs1']['ft-show-colon'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show colon'),
      '#default_value' => $config->get('ft-show-colon'),
      '#description' => t('Show the colon on the reset field template.'),
      '#states' => array(
        'visible' => array(
          'select[name="fs1[ft-default]"]' => array('value' => 'reset'),
          'input[name="fs1[field_template]"]' => array('checked' => TRUE),
        ),
      ),
    );

    return parent::buildForm($form, $form_state);
  }