Example #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.'));
 }
 /**
  * {@inheritdoc}
  */
 public function query()
 {
     // The current payment status item is uniquely identified by the entity ID
     // and the item delta. This plugin is already configured to use the delta
     // for the join. We only need to make sure the entity ID is added to that.
     $this->definition['extra'] = [['field' => 'entity_id', 'left_field' => 'id']];
     parent::query();
 }
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     $vocabularies = entity_load_multiple('taxonomy_vocabulary');
     $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);
 }
Example #4
0
  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    if ($this->options['limit_queue']) {
      $queue = EntityQueue::load($this->options['limit_queue']);
      $dependencies[$queue->getConfigDependencyKey()][] = $queue->getConfigDependencyName();
    }

    return $dependencies;
  }
 /**
  * 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.'));
     }
 }
Example #6
0
 /**
  * Constructs an EntityReverse object.
  *
  * @param \Drupal\views\Plugin\ViewsHandlerManager $join_manager
  *   The views plugin join manager.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, ViewsHandlerManager $join_manager)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->joinManager = $join_manager;
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     $dependencies = parent::calculateDependencies();
     foreach ($this->options['vids'] as $vocabulary_id) {
         if ($vocabulary = $this->vocabularyStorage->load($vocabulary_id)) {
             $dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName();
         }
     }
     return $dependencies;
 }
  /**
   * {@inheritdoc}
   */
  public function query() {
    if (!($flag = $this->getFlag())) {
      return;
    }

    $this->definition['extra'][] = [
      'field' => 'flag_id',
      'value' => $flag->id(),
      'numeric' => TRUE,
    ];

    if ($this->options['user_scope'] == 'current' && !$flag->isGlobal()) {
      $this->definition['extra'][] = [
        'field' => 'uid',
        'value' => '***CURRENT_USER***',
        'numeric' => TRUE,
      ];
      $flag_roles = user_roles(FALSE, "flag $flag->id()");
      if (isset($flag_roles[RoleInterface::ANONYMOUS_ID])) {
        // Disable page caching for anonymous users.
        \Drupal::service('page_cache_kill_switch')->trigger();

        // Add in the SID from Session API for anonymous users.
        $this->definition['extra'][] = [
          'field' => 'sid',
          'value' => '***FLAG_CURRENT_USER_SID***',
          'numeric' => TRUE,
        ];
      }
    }

    parent::query();
  }
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $form['required']['#access'] = FALSE;
 }