Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     // Get the sorts that apply to our base.
     $sorts = Views::viewsDataHelper()->fetchFields($this->definition['base'], 'sort');
     $sort_options = array();
     foreach ($sorts as $sort_id => $sort) {
         $sort_options[$sort_id] = "{$sort['group']}: {$sort['title']}";
     }
     $base_table_data = Views::viewsData()->get($this->definition['base']);
     // Extends the relationship's basic options, allowing the user to pick a
     // sort and an order for it.
     $form['subquery_sort'] = array('#type' => 'select', '#title' => $this->t('Representative sort criteria'), '#default_value' => !empty($this->options['subquery_sort']) ? $this->options['subquery_sort'] : $this->definition['base'] . '.' . $base_table_data['table']['base']['field'], '#options' => $sort_options, '#description' => $this->t("The sort criteria is applied to the data brought in by the relationship to determine how a representative item is obtained for each row. For example, to show the most recent node for each user, pick 'Content: Updated date'."));
     $form['subquery_order'] = array('#type' => 'radios', '#title' => $this->t('Representative sort order'), '#description' => $this->t("The ordering to use for the sort criteria selected above."), '#options' => array('ASC' => $this->t('Ascending'), 'DESC' => $this->t('Descending')), '#default_value' => $this->options['subquery_order']);
     $form['subquery_namespace'] = array('#type' => 'textfield', '#title' => $this->t('Subquery namespace'), '#description' => $this->t('Advanced. Enter a namespace for the subquery used by this relationship.'), '#default_value' => $this->options['subquery_namespace']);
     // WIP: This stuff doesn't work yet: namespacing issues.
     // A list of suitable views to pick one as the subview.
     $views = array('' => '- None -');
     foreach (Views::getAllViews() as $view) {
         // Only get views that are suitable:
         // - base must the base that our relationship joins towards
         // - must have fields.
         if ($view->get('base_table') == $this->definition['base'] && !empty($view->getDisplay('default')['display_options']['fields'])) {
             // TODO: check the field is the correct sort?
             // or let users hang themselves at this stage and check later?
             $views[$view->id()] = $view->id();
         }
     }
     $form['subquery_view'] = array('#type' => 'select', '#title' => $this->t('Representative view'), '#default_value' => $this->options['subquery_view'], '#options' => $views, '#description' => $this->t('Advanced. Use another view to generate the relationship subquery. This allows you to use filtering and more than one sort. If you pick a view here, the sort options above are ignored. Your view must have the ID of its base as its only field, and should have some kind of sorting.'));
     $form['subquery_regenerate'] = array('#type' => 'checkbox', '#title' => $this->t('Generate subquery each time view is run'), '#default_value' => $this->options['subquery_regenerate'], '#description' => $this->t('Will re-generate the subquery for this relationship every time the view is run, instead of only when these options are saved. Use for testing if you are making changes elsewhere. WARNING: seriously impairs performance.'));
 }
Exemple #2
0
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     $vocabularies = $this->vocabularyStorage->loadMultiple();
     $options = array();
     foreach ($vocabularies as $voc) {
         $options[$voc->id()] = $voc->label();
     }
     $form['vids'] = array('#type' => 'checkboxes', '#title' => $this->t('Vocabularies'), '#options' => $options, '#default_value' => $this->options['vids'], '#description' => $this->t('Choose which vocabularies you wish to relate. Remember that every term found will create a new record, so this relationship is best used on just one vocabulary that has only one term per node.'));
     parent::buildOptionsForm($form, $form_state);
 }
 /**
  * Add a delta selector for multiple fields.
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $field = FieldStorageConfig::loadByName($this->definition['target entity type'], $this->definition['field name']);
     $cardinality = $field->getCardinality();
     // Only add the delta selector if the field is multiple.
     if ($field->isMultiple()) {
         $max_delta = $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? 10 : $cardinality;
         $options = array('-1' => t('All'));
         for ($i = 0; $i < $max_delta; $i++) {
             $options[$i] = $i + 1;
         }
         $form['delta'] = array('#type' => 'select', '#options' => $options, '#default_value' => $this->options['delta'], '#title' => t('Delta'), '#description' => t('The delta allows you to select which item in a multiple value field to key the relationship off of. Select "1" to use the first item, "2" for the second item, and so on. If you select "All", each item in the field will create a new row, which may appear to cause duplicates.'));
     }
 }
  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    $queues = EntityQueue::loadMultipleByTargetType($this->getEntityType());
    $options = array();
    foreach ($queues as $queue) {
      $options[$queue->id()] = $queue->label();
    }

    $form['limit_queue'] = array(
      '#type' => 'radios',
      '#title' => $this->t('Limit to a specific entity queue'),
      '#options' => $options,
      '#default_value' => $this->options['limit_queue'],
    );

    parent::buildOptionsForm($form, $form_state);
  }
  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);

    $entity_type = $this->definition['flaggable'];
    $form['label']['#description'] .= ' ' . t('The name of the selected flag makes a good label.');

    $flags = \Drupal::service('flag')->getFlags($entity_type);

    $default_value = $this->options['flag'];
    if (!empty($flags)) {
      $default_value = current(array_keys($flags));
    }

    $form['flag'] = [
      '#type' => 'radios',
      '#title' => t('Flag'),
      '#default_value' => $default_value,
      '#required' => TRUE,
    ];

    foreach ($flags as $flag_id => $flag) {
      if (!empty($flag)) {
        $form['flag']['#options'][$flag_id] = $flag->label();
      }
    }

    $form['user_scope'] = [
      '#type' => 'radios',
      '#title' => t('By'),
      '#options' => ['current' => t('Current user'), 'any' => t('Any user')],
      '#default_value' => $this->options['user_scope'],
    ];

    $form['required']['#title'] = t('Include only flagged content');
    $form['required']['#description'] = t('If checked, only content that has this flag will be included. Leave unchecked to include all content; or, in combination with the <em>Flagged</em> filter, <a href="@unflagged-url">to limit the results to specifically unflagged content</a>.', ['@unflagged-url' => 'http://drupal.org/node/299335']);

    if (!$form['flag']['#options']) {
      $form = [
        'error' => [
          '#markup' => '<p class="error form-item">' . t('No %type flags exist. You must first <a href="@create-url">create a %type flag</a> before being able to use this relationship type.', ['%type' => $entity_type, '@create-url' => Url::fromRoute('entity.flag.collection')->toString()]) . '</p>',
        ],
      ];
    }
  }
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $form['required']['#access'] = FALSE;
 }