Skip to content
Snippets Groups Projects
Commit d729516c authored by catch's avatar catch
Browse files

Issue #3442227 by dww, smustgrave: Use labels in Views argument summaries for entity references

(cherry picked from commit a62995de)
parent ee78369e
No related branches found
Tags 8.x-1.10
35 merge requests!10663Issue #3495778: Update phpdoc in FileSaveHtaccessLoggingTest,!10451Issue #3472458 by watergate, smustgrave: CKEditor 5 show blocks label is not translated,!103032838547 Fix punctuation rules for inline label suffix colon with CSS only,!10150Issue #3467294 by quietone, nod_, smustgrave, catch, longwave: Change string...,!10130Resolve #3480321 "Second level menu",!9936Issue #3483087: Check the module:// prefix in the translation server path and replace it with the actual module path,!9933Issue #3394728 by ankondrat4: Undefined array key "#prefix" and deprecated function: explode() in Drupal\file\Element\ManagedFile::uploadAjaxCallback(),!9914Issue #3451136 by quietone, gapple, ghost of drupal past: Improve...,!9882Draft: Issue #3481777 In bulk_form ensure the triggering element is the bulk_form button,!9839Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9815Issue #3480025: There is no way to remove entity cache items,!9757Issue #3478869 Add "All" or overview links to parent links,!9752Issue #3439910 by pooja_sharma, vensires: Fix Toolbar tests that rely on UID1's super user behavior,!9749Issue #3439910 by pooja_sharma, vensires: Fix Toolbar tests that rely on UID1's super user behavior,!9678Issue #3465132 by catch, Spokje, nod_: Show test run time by class in run-tests.sh output,!9578Issue #3304746 by scott_euser, casey, smustgrave: BigPipe cannot handle (GET)...,!9449Issue #3344041: Allow textarea widgets to be used for text (formatted) fields,!8945🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥...,!8893Resolve #3444391 "Navigation center sm logo",!8772Issue #3445909 by seanB, smustgrave, alexpott, catch: Add static caching to...,!8723Make dblog entities,!8708Filter out disabled display extenders on save,!8691#3459116 - Update Manager Settings: Validate same email address added multiple times,!8665Issue #3449743 by catch: Try to optimize test ordering when run-tests.sh is...,!8598Draft: Issue #3458215: Migrate Toolbar button to SDC,!8572Reorder checkboxes on "Development settings" page,!8538Issue #3457009: Fixing xxception message thrown.,!8516Update file EntityReferenceItem.php,!8505Issue #3456528: _node_mass_update_batch_process fails during user cancel when revision is deleted,!8494Issue #3452511: Convert ProviderRepositoryTest to a kernel test,!8482Resolve #3456202 "Phpunit tests support",!8463Prevent re-install if site already exists,!8392Issue #3454196: Filter placeholders without arguments are not replaced when HTML corrector filter applied afterwards,!8384Issue #3446403 by edutrul, jnicola, mradcliffe: [name]: This field is missing for example recipe,!8304Issue #2990766 by camilledavis, Gauravvvv, mgifford: Location of "Skip to...
Pipeline #187920 passed with warnings
Pipeline: drupal

#187940

    Pipeline: drupal

    #187935

      Pipeline: drupal

      #187931

        ......@@ -61,4 +61,19 @@ public function titleQuery() {
        return $titles;
        }
        /**
        * {@inheritdoc}
        */
        public function summaryName($data) {
        $id = $data->{$this->name_alias};
        $entity = $id ? $this->entityTypeManager->getStorage($this->definition['target_entity_type_id'])->load($id) : NULL;
        if ($entity) {
        return $this->entityRepository->getTranslationFromContext($entity)->label();
        }
        if (($id === NULL || $id === '') && isset($this->definition['empty field name'])) {
        return $this->definition['empty field name'];
        }
        return $id;
        }
        }
        langcode: en
        status: true
        dependencies:
        config:
        - core.entity_view_mode.node.teaser
        - node.type.article
        module:
        - node
        - user
        id: test_argument_summary
        label: test_argument_summary
        module: views
        description: ''
        tag: ''
        base_table: node_field_data
        base_field: nid
        display:
        default:
        id: default
        display_title: Default
        display_plugin: default
        position: 0
        display_options:
        title: test_argument_summary
        fields:
        title:
        id: title
        table: node_field_data
        field: title
        relationship: none
        group_type: group
        admin_label: ''
        entity_type: node
        entity_field: title
        plugin_id: field
        label: ''
        exclude: false
        alter:
        alter_text: false
        make_link: false
        absolute: false
        word_boundary: false
        ellipsis: false
        strip_tags: false
        trim: false
        html: false
        element_type: ''
        element_class: ''
        element_label_type: ''
        element_label_class: ''
        element_label_colon: true
        element_wrapper_type: ''
        element_wrapper_class: ''
        element_default_classes: true
        empty: ''
        hide_empty: false
        empty_zero: false
        hide_alter_empty: true
        click_sort_column: value
        type: string
        settings:
        link_to_entity: true
        group_column: value
        group_columns: { }
        group_rows: true
        delta_limit: 0
        delta_offset: 0
        delta_reversed: false
        delta_first_last: false
        multi_type: separator
        separator: ', '
        field_api_classes: false
        pager:
        type: none
        options:
        offset: 0
        items_per_page: 0
        exposed_form:
        type: basic
        options:
        submit_button: Apply
        reset_button: false
        reset_button_label: Reset
        exposed_sorts_label: 'Sort by'
        expose_sort_order: true
        sort_asc_label: Asc
        sort_desc_label: Desc
        access:
        type: perm
        options:
        perm: 'access content'
        cache:
        type: tag
        options: { }
        empty: { }
        sorts:
        created:
        id: created
        table: node_field_data
        field: created
        relationship: none
        group_type: group
        admin_label: ''
        entity_type: node
        entity_field: created
        plugin_id: date
        order: DESC
        expose:
        label: ''
        field_identifier: ''
        exposed: false
        granularity: second
        arguments:
        field_tags_target_id:
        id: field_tags_target_id
        table: node__field_tags
        field: field_tags_target_id
        relationship: none
        group_type: group
        admin_label: ''
        plugin_id: entity_target_id
        default_action: summary
        exception:
        value: all
        title_enable: false
        title: All
        title_enable: false
        title: ''
        default_argument_type: fixed
        default_argument_options:
        argument: ''
        summary_options:
        base_path: ''
        count: true
        override: false
        items_per_page: 25
        summary:
        sort_order: asc
        number_of_records: 0
        format: default_summary
        specify_validation: false
        validate:
        type: none
        fail: 'not found'
        validate_options: { }
        break_phrase: false
        not: false
        filters:
        status:
        id: status
        table: node_field_data
        field: status
        entity_type: node
        entity_field: status
        plugin_id: boolean
        value: '1'
        group: 1
        expose:
        operator: ''
        type:
        id: type
        table: node_field_data
        field: type
        entity_type: node
        entity_field: type
        plugin_id: bundle
        value:
        article: article
        style:
        type: default
        row:
        type: 'entity:node'
        options:
        view_mode: teaser
        query:
        type: views_query
        options:
        query_comment: ''
        disable_sql_rewrite: false
        distinct: false
        replica: false
        query_tags: { }
        relationships: { }
        header: { }
        footer: { }
        display_extenders: { }
        cache_metadata:
        max-age: -1
        contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url
        - 'user.node_grants:view'
        - user.permissions
        tags: { }
        page_1:
        id: page_1
        display_title: Page
        display_plugin: page
        position: 1
        display_options:
        display_extenders: { }
        path: test-argument-summary
        cache_metadata:
        max-age: -1
        contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url
        - 'user.node_grants:view'
        - user.permissions
        tags: { }
        <?php
        declare(strict_types=1);
        namespace Drupal\Tests\views\Kernel\Handler;
        use Drupal\Core\Field\FieldStorageDefinitionInterface;
        use Drupal\node\NodeTypeInterface;
        use Drupal\taxonomy\VocabularyInterface;
        use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait;
        use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
        use Drupal\node\Entity\Node;
        use Drupal\node\Entity\NodeType;
        use Drupal\taxonomy\Entity\Term;
        use Drupal\taxonomy\TermInterface;
        use Drupal\taxonomy\Entity\Vocabulary;
        use Drupal\views\Views;
        /**
        * Tests the summary of results when an argument is not provided.
        *
        * @group views
        */
        class ArgumentSummaryTest extends ViewsKernelTestBase {
        use EntityReferenceFieldCreationTrait;
        /**
        * {@inheritdoc}
        */
        public static $testViews = ['test_argument_summary'];
        /**
        * {@inheritdoc}
        */
        protected static $modules = [
        'field',
        'node',
        'taxonomy',
        'text',
        'user',
        'views',
        ];
        /**
        * Node type with an autocomplete tagging field.
        *
        * @var \Drupal\node\NodeTypeInterface
        */
        protected NodeTypeInterface $nodeType;
        /**
        * The vocabulary used for the test tag field.
        *
        * @var \Drupal\taxonomy\VocabularyInterface
        */
        protected VocabularyInterface $tagVocabulary;
        /**
        * {@inheritdoc}
        */
        protected function setUp($import_test_views = TRUE): void {
        parent::setUp($import_test_views);
        $this->installEntitySchema('node');
        $this->installEntitySchema('taxonomy_term');
        $this->installEntitySchema('user');
        // Create the content type with an autocomplete tagging field.
        $this->nodeType = NodeType::create([
        'type' => 'article',
        'name' => 'Article',
        ]);
        $this->nodeType->save();
        // Create the vocabulary for the tag field.
        $this->tagVocabulary = Vocabulary::create([
        'name' => 'Views testing tags',
        'vid' => 'views_testing_tags',
        ]);
        $this->tagVocabulary->save();
        // Create the tag field itself.
        $handler_settings = [
        'target_bundles' => [
        $this->tagVocabulary->id() => $this->tagVocabulary->id(),
        ],
        'auto_create' => TRUE,
        ];
        $this->createEntityReferenceField(
        'node',
        $this->nodeType->id(),
        'field_tags',
        NULL,
        'taxonomy_term',
        'default',
        $handler_settings,
        FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
        );
        }
        /**
        * Creates a term in the tag vocabulary.
        *
        * @return \Drupal\taxonomy\TermInterface $term
        */
        protected function createTag(): TermInterface {
        $tag = Term::create([
        'name' => $this->randomMachineName(),
        'vid' => $this->tagVocabulary->id(),
        ]);
        $tag->save();
        return $tag;
        }
        /**
        * Tests the argument summary feature.
        */
        public function testArgumentSummary(): void {
        // Setup 2 tags.
        $tags = [];
        for ($i = 0; $i < 2; $i++) {
        $tags[$i] = $this->createTag();
        }
        // Setup 4 nodes with different tags.
        for ($i = 0; $i < 4; $i++) {
        Node::create([
        'type' => $this->nodeType->id(),
        'title' => $this->randomMachineName(),
        // For odd numbered nodes, use both tags, even only get 1 tag.
        'field_tags' => ($i % 2) ? $tags : [$tags[0]->id()],
        ])->save();
        }
        $view = Views::getView('test_argument_summary');
        $result = $view->preview('default');
        // For the purposes of this test, we don't care about any markup or
        // formatting, only that the summary is showing the tag labels and the
        // correct counts. So strip all tags and extra whitespace to make the
        // assertions more clear.
        $renderer = $this->container->get('renderer');
        $output = (string) $renderer->renderRoot($result);
        $output = trim(preg_replace('/\s+/', ' ', strip_tags($output)));
        // Output should show first tag on 4 nodes, the second tag on only 2.
        $this->assertStringContainsString($tags[0]->label() . ' (4)', $output);
        $this->assertStringContainsString($tags[1]->label() . ' (2)', $output);
        }
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment