Example #1
0
 /**
  * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayOptions().
  */
 protected function defaultDisplayOptions()
 {
     $display_options = parent::defaultDisplayOptions();
     // Add permission-based access control.
     $display_options['access']['type'] = 'perm';
     // Remove the default fields, since we are customizing them here.
     unset($display_options['fields']);
     /* Field: File: Name */
     $display_options['fields']['filename']['id'] = 'filename';
     $display_options['fields']['filename']['table'] = 'file_managed';
     $display_options['fields']['filename']['field'] = 'filename';
     $display_options['fields']['filename']['entity_type'] = 'file';
     $display_options['fields']['filename']['entity_field'] = 'filename';
     $display_options['fields']['filename']['label'] = '';
     $display_options['fields']['filename']['alter']['alter_text'] = 0;
     $display_options['fields']['filename']['alter']['make_link'] = 0;
     $display_options['fields']['filename']['alter']['absolute'] = 0;
     $display_options['fields']['filename']['alter']['trim'] = 0;
     $display_options['fields']['filename']['alter']['word_boundary'] = 0;
     $display_options['fields']['filename']['alter']['ellipsis'] = 0;
     $display_options['fields']['filename']['alter']['strip_tags'] = 0;
     $display_options['fields']['filename']['alter']['html'] = 0;
     $display_options['fields']['filename']['hide_empty'] = 0;
     $display_options['fields']['filename']['empty_zero'] = 0;
     $display_options['fields']['filename']['plugin_id'] = 'field';
     $display_options['fields']['filename']['type'] = 'file_link';
     return $display_options;
 }
Example #2
0
 /**
  * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayOptions().
  */
 protected function defaultDisplayOptions()
 {
     $display_options = parent::defaultDisplayOptions();
     // Add permission-based access control.
     $display_options['access']['type'] = 'perm';
     $display_options['access']['options']['perm'] = 'access user profiles';
     // Remove the default fields, since we are customizing them here.
     unset($display_options['fields']);
     /* Field: User: Name */
     $display_options['fields']['name']['id'] = 'name';
     $display_options['fields']['name']['table'] = 'users_field_data';
     $display_options['fields']['name']['field'] = 'name';
     $display_options['fields']['name']['entity_type'] = 'user';
     $display_options['fields']['name']['entity_field'] = 'name';
     $display_options['fields']['name']['label'] = '';
     $display_options['fields']['name']['alter']['alter_text'] = 0;
     $display_options['fields']['name']['alter']['make_link'] = 0;
     $display_options['fields']['name']['alter']['absolute'] = 0;
     $display_options['fields']['name']['alter']['trim'] = 0;
     $display_options['fields']['name']['alter']['word_boundary'] = 0;
     $display_options['fields']['name']['alter']['ellipsis'] = 0;
     $display_options['fields']['name']['alter']['strip_tags'] = 0;
     $display_options['fields']['name']['alter']['html'] = 0;
     $display_options['fields']['name']['hide_empty'] = 0;
     $display_options['fields']['name']['empty_zero'] = 0;
     $display_options['fields']['name']['link_to_user'] = 1;
     $display_options['fields']['name']['overwrite_anonymous'] = 0;
     $display_options['fields']['name']['plugin_id'] = 'user_name';
     return $display_options;
 }
Example #3
0
 /**
  * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayOptions().
  */
 protected function defaultDisplayOptions()
 {
     $display_options = parent::defaultDisplayOptions();
     // Add permission-based access control.
     $display_options['access']['type'] = 'perm';
     $display_options['access']['provider'] = 'user';
     // Remove the default fields, since we are customizing them here.
     unset($display_options['fields']);
     /* Field: Taxonomy: Term */
     $display_options['fields']['name']['id'] = 'name';
     $display_options['fields']['name']['table'] = 'taxonomy_term_data';
     $display_options['fields']['name']['field'] = 'name';
     $display_options['fields']['name']['provider'] = 'taxonomy';
     $display_options['fields']['name']['label'] = '';
     $display_options['fields']['name']['alter']['alter_text'] = 0;
     $display_options['fields']['name']['alter']['make_link'] = 0;
     $display_options['fields']['name']['alter']['absolute'] = 0;
     $display_options['fields']['name']['alter']['trim'] = 0;
     $display_options['fields']['name']['alter']['word_boundary'] = 0;
     $display_options['fields']['name']['alter']['ellipsis'] = 0;
     $display_options['fields']['name']['alter']['strip_tags'] = 0;
     $display_options['fields']['name']['alter']['html'] = 0;
     $display_options['fields']['name']['hide_empty'] = 0;
     $display_options['fields']['name']['empty_zero'] = 0;
     $display_options['fields']['name']['link_to_taxonomy'] = 1;
     return $display_options;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 protected function defaultDisplayOptions()
 {
     $display_options = parent::defaultDisplayOptions();
     // Add permission-based access control.
     $display_options['access']['type'] = 'perm';
     $display_options['access']['options']['perm'] = 'access content';
     // Remove the default fields, since we are customizing them here.
     unset($display_options['fields']);
     // Add the name field, so that the display has content if the user switches
     // to a row style that uses fields.
     /* Field: Media: Name */
     $display_options['fields']['name']['id'] = 'name';
     $display_options['fields']['name']['table'] = 'media_field_data';
     $display_options['fields']['name']['field'] = 'name';
     $display_options['fields']['name']['entity_type'] = 'media';
     $display_options['fields']['name']['entity_field'] = 'media';
     $display_options['fields']['name']['label'] = '';
     $display_options['fields']['name']['alter']['alter_text'] = 0;
     $display_options['fields']['name']['alter']['make_link'] = 0;
     $display_options['fields']['name']['alter']['absolute'] = 0;
     $display_options['fields']['name']['alter']['trim'] = 0;
     $display_options['fields']['name']['alter']['word_boundary'] = 0;
     $display_options['fields']['name']['alter']['ellipsis'] = 0;
     $display_options['fields']['name']['alter']['strip_tags'] = 0;
     $display_options['fields']['name']['alter']['html'] = 0;
     $display_options['fields']['name']['hide_empty'] = 0;
     $display_options['fields']['name']['empty_zero'] = 0;
     $display_options['fields']['name']['settings']['link_to_entity'] = 1;
     $display_options['fields']['name']['plugin_id'] = 'field';
     return $display_options;
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 protected function defaultDisplayOptions()
 {
     $display_options = parent::defaultDisplayOptions();
     // Add permission-based access control.
     $display_options['access']['type'] = 'perm';
     $display_options['access']['options']['perm'] = 'access site reports';
     return $display_options;
 }
 /**
  * Tests the creating of a view.
  *
  * @see \Drupal\views\Plugin\views\wizard\WizardPluginBase
  */
 public function testCreateView()
 {
     $form = array();
     $form_state = new FormState();
     $form = $this->wizard->buildForm($form, $form_state);
     $random_id = strtolower($this->randomMachineName());
     $random_label = $this->randomMachineName();
     $random_description = $this->randomMachineName();
     // Add a new language and mark it as default.
     ConfigurableLanguage::createFromLangcode('it')->save();
     $this->config('system.site')->set('default_langcode', 'it')->save();
     $form_state->setValues(['id' => $random_id, 'label' => $random_label, 'description' => $random_description, 'base_table' => 'views_test_data']);
     $this->wizard->validateView($form, $form_state);
     $view = $this->wizard->createView($form, $form_state);
     $this->assertTrue($view instanceof ViewUI, 'The created view is a ViewUI object.');
     $this->assertEqual($view->get('id'), $random_id);
     $this->assertEqual($view->get('label'), $random_label);
     $this->assertEqual($view->get('description'), $random_description);
     $this->assertEqual($view->get('base_table'), 'views_test_data');
     $this->assertEqual($view->get('langcode'), 'it');
 }
 /**
  * Tests the creating of a view.
  *
  * @see \Drupal\views\Plugin\views\wizard\WizardPluginBase
  */
 public function testCreateView()
 {
     $form = array();
     $form_state = new FormState();
     $form = $this->wizard->buildForm($form, $form_state);
     $random_id = strtolower($this->randomMachineName());
     $random_label = $this->randomMachineName();
     $random_description = $this->randomMachineName();
     // Add a new language and mark it as default.
     $language = new Language(array('id' => 'it', 'name' => 'Italian', 'default' => TRUE));
     language_save($language);
     $form_state['values'] = array('id' => $random_id, 'label' => $random_label, 'description' => $random_description, 'base_table' => 'views_test_data');
     $this->wizard->validateView($form, $form_state);
     $view = $this->wizard->createView($form, $form_state);
     $this->assertTrue($view instanceof ViewUI, 'The created view is a ViewUI object.');
     $this->assertEqual($view->get('id'), $random_id);
     $this->assertEqual($view->get('label'), $random_label);
     $this->assertEqual($view->get('description'), $random_description);
     $this->assertEqual($view->get('base_table'), 'views_test_data');
     $this->assertEqual($view->get('langcode'), 'it');
 }
Example #8
0
 /**
  * @covers ::getSelected
  *
  * @dataProvider providerTestGetSelected
  */
 public function testGetSelected($expected, $element = [], $parents = [], $user_input = [], $not_rebuilding_expected = NULL)
 {
     $not_rebuilding_expected = $not_rebuilding_expected ?: $expected;
     $form_state = new FormState();
     $form_state->setUserInput($user_input);
     $actual = WizardPluginBase::getSelected($form_state, $parents, 'the_default_value', $element);
     $this->assertSame($not_rebuilding_expected, $actual);
     $this->assertSame($user_input, $form_state->getUserInput());
     $form_state->setRebuild();
     $actual = WizardPluginBase::getSelected($form_state, $parents, 'the_default_value', $element);
     $this->assertSame($expected, $actual);
     $this->assertSame($user_input, $form_state->getUserInput());
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 protected function defaultDisplayOptions()
 {
     $display_options = parent::defaultDisplayOptions();
     // Add permission-based access control.
     $display_options['access']['type'] = 'perm';
     $display_options['access']['options']['perm'] = 'view all revisions';
     // Remove the default fields, since we are customizing them here.
     unset($display_options['fields']);
     /* Field: Content revision: Created date */
     $display_options['fields']['changed']['id'] = 'changed';
     $display_options['fields']['changed']['table'] = 'node_field_revision';
     $display_options['fields']['changed']['field'] = 'changed';
     $display_options['fields']['changed']['entity_type'] = 'node';
     $display_options['fields']['changed']['entity_field'] = 'changed';
     $display_options['fields']['changed']['alter']['alter_text'] = FALSE;
     $display_options['fields']['changed']['alter']['make_link'] = FALSE;
     $display_options['fields']['changed']['alter']['absolute'] = FALSE;
     $display_options['fields']['changed']['alter']['trim'] = FALSE;
     $display_options['fields']['changed']['alter']['word_boundary'] = FALSE;
     $display_options['fields']['changed']['alter']['ellipsis'] = FALSE;
     $display_options['fields']['changed']['alter']['strip_tags'] = FALSE;
     $display_options['fields']['changed']['alter']['html'] = FALSE;
     $display_options['fields']['changed']['hide_empty'] = FALSE;
     $display_options['fields']['changed']['empty_zero'] = FALSE;
     $display_options['fields']['changed']['plugin_id'] = 'field';
     $display_options['fields']['changed']['type'] = 'timestamp';
     $display_options['fields']['changed']['settings']['date_format'] = 'medium';
     $display_options['fields']['changed']['settings']['custom_date_format'] = '';
     $display_options['fields']['changed']['settings']['timezone'] = '';
     /* Field: Content revision: Title */
     $display_options['fields']['title']['id'] = 'title';
     $display_options['fields']['title']['table'] = 'node_field_revision';
     $display_options['fields']['title']['field'] = 'title';
     $display_options['fields']['title']['entity_type'] = 'node';
     $display_options['fields']['title']['entity_field'] = 'title';
     $display_options['fields']['title']['label'] = '';
     $display_options['fields']['title']['alter']['alter_text'] = 0;
     $display_options['fields']['title']['alter']['make_link'] = 0;
     $display_options['fields']['title']['alter']['absolute'] = 0;
     $display_options['fields']['title']['alter']['trim'] = 0;
     $display_options['fields']['title']['alter']['word_boundary'] = 0;
     $display_options['fields']['title']['alter']['ellipsis'] = 0;
     $display_options['fields']['title']['alter']['strip_tags'] = 0;
     $display_options['fields']['title']['alter']['html'] = 0;
     $display_options['fields']['title']['hide_empty'] = 0;
     $display_options['fields']['title']['empty_zero'] = 0;
     $display_options['fields']['title']['settings']['link_to_entity'] = 0;
     $display_options['fields']['title']['plugin_id'] = 'field';
     return $display_options;
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form['#attached']['css'] = static::getAdminCSS();
     $form['#attached']['js'][] = drupal_get_path('module', 'views_ui') . '/js/views-admin.js';
     $form['#attributes']['class'] = array('views-admin');
     $form['name'] = array('#type' => 'fieldset', '#title' => t('View basic information'), '#attributes' => array('class' => array('fieldset-no-legend')));
     $form['name']['label'] = array('#type' => 'textfield', '#title' => $this->t('View name'), '#required' => TRUE, '#size' => 32, '#default_value' => '', '#maxlength' => 255);
     $form['name']['id'] = array('#type' => 'machine_name', '#maxlength' => 128, '#machine_name' => array('exists' => '\\Drupal\\views\\Views::getView', 'source' => array('name', 'label')), '#description' => $this->t('A unique machine-readable name for this View. It must only contain lowercase letters, numbers, and underscores.'));
     $form['name']['description_enable'] = array('#type' => 'checkbox', '#title' => $this->t('Description'));
     $form['name']['description'] = array('#type' => 'textfield', '#title' => $this->t('Provide description'), '#title_display' => 'invisible', '#size' => 64, '#default_value' => '', '#states' => array('visible' => array(':input[name="description_enable"]' => array('checked' => TRUE))));
     // Create a wrapper for the entire dynamic portion of the form. Everything
     // that can be updated by AJAX goes somewhere inside here. For example, this
     // is needed by "Show" dropdown (below); it changes the base table of the
     // view and therefore potentially requires all options on the form to be
     // dynamically updated.
     $form['displays'] = array();
     // Create the part of the form that allows the user to select the basic
     // properties of what the view will display.
     $form['displays']['show'] = array('#type' => 'fieldset', '#title' => t('View settings'), '#tree' => TRUE, '#attributes' => array('class' => array('container-inline')));
     // Create the "Show" dropdown, which allows the base table of the view to be
     // selected.
     $wizard_plugins = $this->wizardManager->getDefinitions();
     $options = array();
     foreach ($wizard_plugins as $key => $wizard) {
         $options[$key] = $wizard['title'];
     }
     $form['displays']['show']['wizard_key'] = array('#type' => 'select', '#title' => $this->t('Show'), '#options' => $options);
     $show_form =& $form['displays']['show'];
     $default_value = \Drupal::moduleHandler()->moduleExists('node') ? 'node' : 'users';
     $show_form['wizard_key']['#default_value'] = WizardPluginBase::getSelected($form_state, array('show', 'wizard_key'), $default_value, $show_form['wizard_key']);
     // Changing this dropdown updates the entire content of $form['displays'] via
     // AJAX.
     views_ui_add_ajax_trigger($show_form, 'wizard_key', array('displays'));
     // Build the rest of the form based on the currently selected wizard plugin.
     $wizard_key = $show_form['wizard_key']['#default_value'];
     $wizard_instance = $this->wizardManager->createInstance($wizard_key);
     $form = $wizard_instance->buildForm($form, $form_state);
     return $form;
 }
Example #11
0
 /**
  * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayOptions().
  */
 protected function defaultDisplayOptions()
 {
     $display_options = parent::defaultDisplayOptions();
     // Add permission-based access control.
     $display_options['access']['type'] = 'perm';
     $display_options['access']['options']['perm'] = 'access comments';
     // Add a relationship to nodes.
     $display_options['relationships']['node']['id'] = 'node';
     $display_options['relationships']['node']['table'] = 'comment_field_data';
     $display_options['relationships']['node']['field'] = 'node';
     $display_options['relationships']['node']['entity_type'] = 'comment_field_data';
     $display_options['relationships']['node']['required'] = 1;
     $display_options['relationships']['node']['plugin_id'] = 'standard';
     // Remove the default fields, since we are customizing them here.
     unset($display_options['fields']);
     /* Field: Comment: Title */
     $display_options['fields']['subject']['id'] = 'subject';
     $display_options['fields']['subject']['table'] = 'comment_field_data';
     $display_options['fields']['subject']['field'] = 'subject';
     $display_options['fields']['subject']['entity_type'] = 'comment';
     $display_options['fields']['subject']['entity_field'] = 'subject';
     $display_options['fields']['subject']['label'] = '';
     $display_options['fields']['subject']['alter']['alter_text'] = 0;
     $display_options['fields']['subject']['alter']['make_link'] = 0;
     $display_options['fields']['subject']['alter']['absolute'] = 0;
     $display_options['fields']['subject']['alter']['trim'] = 0;
     $display_options['fields']['subject']['alter']['word_boundary'] = 0;
     $display_options['fields']['subject']['alter']['ellipsis'] = 0;
     $display_options['fields']['subject']['alter']['strip_tags'] = 0;
     $display_options['fields']['subject']['alter']['html'] = 0;
     $display_options['fields']['subject']['hide_empty'] = 0;
     $display_options['fields']['subject']['empty_zero'] = 0;
     $display_options['fields']['subject']['plugin_id'] = 'field';
     $display_options['fields']['subject']['type'] = 'string';
     $display_options['fields']['subject']['settings'] = ['link_to_entity' => TRUE];
     return $display_options;
 }
Example #12
0
 /**
  * Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::buildFilters().
  *
  * Add some options for filter by taxonomy terms.
  */
 protected function buildFilters(&$form, FormStateInterface $form_state)
 {
     parent::buildFilters($form, $form_state);
     $selected_bundle = static::getSelected($form_state, array('show', 'type'), 'all', $form['displays']['show']['type']);
     // Add the "tagged with" filter to the view.
     // We construct this filter using taxonomy_index.tid (which limits the
     // filtering to a specific vocabulary) rather than
     // taxonomy_term_field_data.name (which matches terms in any vocabulary).
     // This is because it is a more commonly-used filter that works better with
     // the autocomplete UI, and also to avoid confusion with other vocabularies
     // on the site that may have terms with the same name but are not used for
     // free tagging.
     // The downside is that if there *is* more than one vocabulary on the site
     // that is used for free tagging, the wizard will only be able to make the
     // "tagged with" filter apply to one of them (see below for the method it
     // uses to choose).
     // Find all "tag-like" taxonomy fields associated with the view's
     // entities. If a particular entity type (i.e., bundle) has been
     // selected above, then we only search for taxonomy fields associated
     // with that bundle. Otherwise, we use all bundles.
     $bundles = array_keys(entity_get_bundles($this->entityTypeId));
     // Double check that this is a real bundle before using it (since above
     // we added a dummy option 'all' to the bundle list on the form).
     if (isset($selected_bundle) && in_array($selected_bundle, $bundles)) {
         $bundles = array($selected_bundle);
     }
     $tag_fields = array();
     foreach ($bundles as $bundle) {
         $display = entity_get_form_display($this->entityTypeId, $bundle, 'default');
         $taxonomy_fields = array_filter(\Drupal::entityManager()->getFieldDefinitions($this->entityTypeId, $bundle), function ($field_definition) {
             return $field_definition->getType() == 'entity_reference' && $field_definition->getSetting('target_type') == 'taxonomy_term';
         });
         foreach ($taxonomy_fields as $field_name => $field) {
             $widget = $display->getComponent($field_name);
             // We define "tag-like" taxonomy fields as ones that use the
             // "Autocomplete (Tags style)" widget.
             if ($widget['type'] == 'entity_reference_autocomplete_tags') {
                 $tag_fields[$field_name] = $field;
             }
         }
     }
     if (!empty($tag_fields)) {
         // If there is more than one "tag-like" taxonomy field available to
         // the view, we can only make our filter apply to one of them (as
         // described above). We choose 'field_tags' if it is available, since
         // that is created by the Standard install profile in core and also
         // commonly used by contrib modules; thus, it is most likely to be
         // associated with the "main" free-tagging vocabulary on the site.
         if (array_key_exists('field_tags', $tag_fields)) {
             $tag_field_name = 'field_tags';
         } else {
             $tag_field_name = key($tag_fields);
         }
         // Add the autocomplete textfield to the wizard.
         $target_bundles = $tag_fields[$tag_field_name]->getSetting('handler_settings')['target_bundles'];
         $form['displays']['show']['tagged_with'] = array('#type' => 'entity_autocomplete', '#title' => $this->t('tagged with'), '#target_type' => 'taxonomy_term', '#selection_settings' => ['target_bundles' => $target_bundles], '#tags' => TRUE, '#size' => 30, '#maxlength' => 1024);
     }
 }