/** * {@inheritdoc} */ public function render($row) { $build = parent::render($row); if (!$this->options['links']) { unset($build['links']); } return $build; }
/** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); // Use view mode of display settings. if ($this->entityType == 'node' && \Drupal::moduleHandler()->moduleExists('ds_switch_view_mode')) { $form['switch_fieldset'] = array('#type' => 'details', '#title' => t('Use view mode of display settings'), '#open' => $this->options['switch_fieldset']['switch']); $form['switch_fieldset']['switch'] = array('#type' => 'checkbox', '#title' => t('Use view mode of display settings'), '#default_value' => $this->options['switch_fieldset']['switch'], '#description' => t('Use the alternative view mode selected in the display settings tab.')); } // Alternating view modes. $form['alternating_fieldset'] = array('#type' => 'details', '#title' => t('Alternating view mode'), '#open' => $this->options['alternating_fieldset']['alternating']); $form['alternating_fieldset']['alternating'] = array('#type' => 'checkbox', '#title' => t('Use the changing view mode selector'), '#default_value' => $this->options['alternating_fieldset']['alternating']); $form['alternating_fieldset']['allpages'] = array('#type' => 'checkbox', '#title' => t('Use this configuration on every page. Otherwhise the default view mode is used as soon you browse away from the first page of this view.'), '#default_value' => isset($this->options['alternating_fieldset']['allpages']) ? $this->options['alternating_fieldset']['allpages'] : FALSE); $pager = $this->view->display_handler->getPlugin('pager'); $limit = $pager->getItemsPerPage(); if ($limit == 0 || $limit > 20) { $form['alternating_fieldset']['disabled'] = array('#markup' => t('This option is disabled because you have unlimited items or listing more than 20 items.')); $form['alternating_fieldset']['alternating']['#disabled'] = TRUE; $form['alternating_fieldset']['allpages']['#disabled'] = TRUE; } else { $i = 1; $a = 0; while ($limit != 0) { $form['alternating_fieldset']['item_' . $a] = ['#title' => t('Item @nr', array('@nr' => $i)), '#type' => 'select', '#default_value' => isset($this->options['alternating_fieldset']['item_' . $a]) ? $this->options['alternating_fieldset']['item_' . $a] : 'teaser', '#options' => \Drupal::service('entity_display.repository')->getViewModeOptions($this->entityTypeId)]; $limit--; $a++; $i++; } } // Grouping rows $sorts = $this->view->display_handler->getOption('sorts'); $groupable = !empty($sorts) && $this->options['grouping_fieldset']['group']; $form['grouping_fieldset'] = array('#type' => 'details', '#title' => t('Group data'), '#open' => $groupable); $form['grouping_fieldset']['group'] = array('#type' => 'checkbox', '#title' => t('Group data on a field. The value of this field will be displayed too.'), '#default_value' => $groupable); if (!empty($sorts)) { $sort_options = array(); foreach ($sorts as $sort) { $sort_name = Unicode::ucfirst($sort['field']); $sort_options[$sort['table'] . '|' . $sort['field']] = $sort_name; } $form['grouping_fieldset']['group_field'] = array('#type' => 'select', '#options' => $sort_options, '#default_value' => isset($this->options['grouping_fieldset']['group_field']) ? $this->options['grouping_fieldset']['group_field'] : ''); $form['grouping_fieldset']['group_field_function'] = array('#type' => 'textfield', '#title' => 'Heading function', '#description' => Html::escape(t('The value of the field can be in a very raw format (eg, date created). Enter a custom function which you can use to format that value. The value and the object will be passed into that function eg. custom_function($raw_value, $object);')), '#default_value' => isset($this->options['grouping_fieldset']['group_field_function']) ? $this->options['grouping_fieldset']['group_field_function'] : ''); } else { $form['grouping_fieldset']['group']['#disabled'] = TRUE; $form['grouping_fieldset']['group']['#description'] = t('Grouping is disabled because you do not have any sort fields.'); } // Advanced function. $form['advanced_fieldset'] = array('#type' => 'details', '#title' => t('Advanced view mode'), '#open' => $this->options['advanced_fieldset']['advanced']); $form['advanced_fieldset']['advanced'] = array('#type' => 'checkbox', '#title' => t('Use the advanced view mode selector'), '#description' => t('This gives you the opportunity to have full control of a list for really advanced features.<br /> There is no UI for this, you need to create a hook named like this: hook_ds_views_row_render_entity($entity, $view_mode).', array('@VIEWSNAME' => $this->view->storage->id())), '#default_value' => $this->options['advanced_fieldset']['advanced']); }
/** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $form['links'] = array('#type' => 'checkbox', '#title' => t('Display links'), '#default_value' => $this->options['links']); }
/** * {@inheritdoc} */ protected function defineOptions() { $options = parent::defineOptions(); $options['view_mode']['default'] = 'full'; return $options; }