Problem/Motivation

There is no way in views to set the default value of entity field argument.

Proposed resolution

Create argument_default plugin for entity field value which will allow entity field argument to have default value.

Remaining tasks

Tests
Review

User interface changes

New argument_default plugin

API changes

None

Data model changes

None

Comments

jibran created an issue. See original summary.

jibran’s picture

Status: Active » Needs review
StatusFileSize
new6.77 KB
dawehner’s picture

There is no reason that this is added in ctools. This is core feature we should add.

jibran’s picture

Project: Chaos Tool Suite (ctools) » Drupal core
Version: 8.x-3.x-dev » 8.3.x-dev
Component: Code » views.module
Issue tags: +VDC, +Need tests
StatusFileSize
new7.47 KB

The form needs to ajaxify and we need tests.

jibran’s picture

Issue summary: View changes

Updated issue summary.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

  1. +++ b/core/modules/views/src/Plugin/views/argument_default/EntityField.php
    @@ -0,0 +1,191 @@
    +    $labels = $this->entityTypeRepository->getEntityTypeLabels(TRUE);
    +    $options = $labels[(string) t('Content', [], ['context' => 'Entity type group'])];
    

    we used to get rid of module group name as key... any reason to use translation as key?

  2. +++ b/core/modules/views/src/Plugin/views/argument_default/EntityField.php
    @@ -0,0 +1,191 @@
    +      // @todo add AJAX to the select.
    +      $form['field'] = [
    +        '#type' => 'select',
    

    needs issue or work here

  3. +++ b/core/modules/views/src/Plugin/views/argument_default/EntityField.php
    @@ -0,0 +1,191 @@
    +    if (strpos($route_name, 'entity.') === 0) {
    +      list (, $entity_type_id,) = explode('.', $route_name);
    +      if (($entity = $this->routeMatch->getParameter($entity_type_id)) && $entity instanceof ContentEntityInterface && $entity_type_id === $this->options['entity_type'] && ($field = $this->options['field'])) {
    

    this looks scary to parse route name,
    I bet it easy to iterate through route match params with checking for FieldableInterface and names

jibran’s picture

Re: #7:

  1. This is used in a lot of places in core field_ui is one of those hence the translated key.
  2. Needs work.
  3. We standardize the route names for a reason but I'm open to improvements.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

acbramley’s picture

Status: Needs review » Needs work

From some manual testing it looks like there's a small bug when editing an existing contextual filter that was using a different plugin and changing it to this one. The Field dropdown doesn't appear and there's a JS error output:

Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'option'
    at Function.error (http://127.0.0.1/core/assets/vendor/jquery/jquery.min.js?v=3.2.1:2:1979)
    at HTMLDivElement.<anonymous> (http://127.0.0.1/core/assets/vendor/jquery.ui/ui/widget-min.js?v=1.12.1:4:2205)
    at Function.each (http://127.0.0.1/core/assets/vendor/jquery/jquery.min.js?v=3.2.1:2:2715)
    at r.fn.init.each (http://127.0.0.1/core/assets/vendor/jquery/jquery.min.js?v=3.2.1:2:1003)
    at r.fn.init.a.fn.(anonymous function) [as dialog] (http://127.0.0.1/core/assets/vendor/jquery.ui/ui/widget-min.js?v=1.12.1:4:1947)
    at resetSize (<anonymous>:37:25)
    at later (http://127.0.0.1/core/misc/debounce.js?v=8.4.4:17:23)
jibran’s picture

The form needs to ajaxify and we need tests.

:P

acbramley’s picture

My bad!! XD

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

larowlan’s picture

This also needs to work on node-revision pages, does not at present

jibran’s picture

We need an API from core to provide entity object from route param, i.e. D9 version of menu_get_object(). In D8, metatag_get_route_entity() doing the same thing. Also, see the discussion after #18 in #2847224: Add views argument_default for getting Entity ID from URL.

claudiu.cristea’s picture

Issue tags: -Need tests +Needs tests

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kim.pepper’s picture

Issue tags: +#pnx-sprint

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

cman9090’s picture

StatusFileSize
new10.24 KB

After trying patch #4, there was a few things not working but luckily a fully functioning plugin module has been written.

https://www.drupal.org/project/views_arg_entity_field

I've copied this plugin code and applied as a patch for core consideration.

jibran’s picture

Can you please add some screenshots and maybe tests as well? We should keep the plugin name the same so that it won't break for the existing sites using this patch or the module.

ranjith_kumar_k_u’s picture

StatusFileSize
new10.14 KB
new2.48 KB

Fixed CS errors

ravi.shankar’s picture

StatusFileSize
new10.06 KB
new859 bytes

Fixed Drupal CS issue of patch #27.

cman9090’s picture

StatusFileSize
new10.02 KB

do not use.

cman9090’s picture

do not use

cman9090’s picture

StatusFileSize
new9.9 KB

Example
Updated patch with CS fixes and renamed the plugin name to the original patch plugin name.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.