usesFields example

/** * Return TRUE if this style also uses fields. * * @return bool */
  public function usesFields() {
    // If we use a row plugin, ask the row plugin. Chances are, we don't     // care, it does.     $row_uses_fields = FALSE;
    if ($this->usesRowPlugin() && ($row_plugin = $this->displayHandler->getPlugin('row'))) {
      $row_uses_fields = $row_plugin->usesFields();
    }
    // Otherwise, check the definition or the option.     return $row_uses_fields || $this->usesFields || !empty($this->options['uses_fields']);
  }

  /** * Return TRUE if this style uses tokens. * * Used to ensure we don't fetch tokens when not needed for performance. */
  public function usesTokens() {
    
'#title' => $this->t('Default column classes'),
      '#description' => $this->t('Add the default views column classes like views-col, col-1 and clearfix to the output. You can use this to quickly reduce the amount of markup the view provides by default, at the cost of making it more difficult to apply CSS.'),
      '#type' => 'checkbox',
      '#default_value' => $this->options['col_class_default'],
    ];
    $form['col_class_custom'] = [
      '#title' => $this->t('Custom column class'),
      '#description' => $this->t('Additional classes to provide on each column. Separated by a space.'),
      '#type' => 'textfield',
      '#default_value' => $this->options['col_class_custom'],
    ];
    if ($this->usesFields()) {
      $form['col_class_custom']['#description'] .= ' ' . $this->t('You may use field tokens from as per the "Replacement patterns" used in "Rewrite the output of this field" for all fields.');
    }
    $form['row_class_default'] = [
      '#title' => $this->t('Default row classes'),
      '#description' => $this->t('Adds the default views row classes like views-row, row-1 and clearfix to the output. You can use this to quickly reduce the amount of markup the view provides by default, at the cost of making it more difficult to apply CSS.'),
      '#type' => 'checkbox',
      '#default_value' => $this->options['row_class_default'],
    ];
    $form['row_class_custom'] = [
      '#title' => $this->t('Custom row class'),
      '#description' => $this->t('Additional classes to provide on each row. Separated by a space.'),
      


    if (\array_key_exists($option$this->options)) {
      return $this->options[$option];
    }
  }

  /** * {@inheritdoc} */
  public function usesFields() {
    return $this->getPlugin('style')->usesFields();
  }

  /** * {@inheritdoc} */
  public function getPlugin($type) {
    // Look up the plugin name to use for this instance.     $options = $this->getOption($type);

    // Return now if no options have been loaded.     if (empty($options) || !isset($options['type'])) {
      
$options = parent::defineOptions();
    $options['fields'] = ['default' => []];

    return $options;
  }

  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);
    $this->view->initStyle();

    // Allow to choose all fields as possible     if ($this->view->style_plugin->usesFields()) {
      $options = [];
      foreach ($this->view->display_handler->getHandlers('field') as $name => $field) {
        // Only allow clickSortable fields. Fields without clickSorting will         // probably break in the Combine filter.         if ($field->clickSortable()) {
          $options[$name] = $field->adminLabel(TRUE);
        }
      }
      if ($options) {
        $form['fields'] = [
          '#type' => 'select',
          
$default_value = $block_with_linked_titles_available ? 'titles_linked' : key($options);
      $style_form['row_plugin']['#default_value'] = static::getSelected($form_state[$type, 'style', 'row_plugin']$default_value$style_form['row_plugin']);
      // Changing this dropdown updates the individual row options via AJAX.       views_ui_add_ajax_trigger($style_form, 'row_plugin', ['displays', $type, 'options', 'style', 'row_options']);

      // This is the region that can be updated by AJAX. The base class doesn't       // add anything here, but child classes can.       $style_form['row_options'] = [
        '#theme_wrappers' => ['container'],
      ];
    }
    elseif ($style_plugin->usesFields()) {
      $style_form['row_plugin'] = ['#markup' => '<span>' . $this->t('of fields') . '</span>'];
    }
  }

  /** * Retrieves row style plugin names. * * @return array * Returns the plugin names available for the base table of the wizard. */
  protected function rowStyleOptions() {
    
return $this->built;
    }

    // Initialize the style; arguments may have changed which style we use,     // so waiting as long as possible is important. But we need to know     // about the style when we go to build fields.     if (!$this->initStyle()) {
      $this->build_info['fail'] = TRUE;
      return FALSE;
    }

    if ($this->style_plugin->usesFields()) {
      $this->_build('field');
    }

    // Build our sort criteria if we were instructed to do so.     if (!empty($this->build_sort)) {
      // Allow the style handler to deal with sorting.       if ($this->style_plugin->buildSort()) {
        $this->_build('sort');
      }
      // allow the plugin to build second sorts as well.       $this->style_plugin->buildSortPost();
    }
case 'filter':
        // The rearrange form for filters contains the and/or UI, so override         // the used path.         $rearrange_url = Url::fromRoute('views_ui.form_rearrange_filter', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display['id']]);
        // TODO: Add another class to have another symbol for filter rearrange.         $class = 'icon compact rearrange';
        break;

      case 'field':
        // Fetch the style plugin info so we know whether to list fields or not.         $style_plugin = $executable->style_plugin;
        $uses_fields = $style_plugin && $style_plugin->usesFields();
        if (!$uses_fields) {
          $build['fields'][] = [
            '#markup' => $this->t('The selected style or row format does not use fields.'),
            '#theme_wrappers' => ['views_ui_container'],
            '#attributes' => ['class' => ['views-display-setting']],
          ];
          return $build;
        }
        break;

      case 'header':
      
Home | Imprint | This part of the site doesn't use cookies.