Problem/Motivation

While looking into #2778569: REST views: Consider implementing `attachTo` method in `RestExport` display plugin, I realized that several Views style plugins have a attachTo method. In some places the docblock uses {@inheritdoc}, in other places there is no docblock. Either way, this method is not part of the ViewsPluginBase class.

This impacts the 2 feed style plugins: OPML and RSS.

Proposed resolution

Add a new interface AttachableStyle or similar, that defines this method.

The code in \Drupal\views\Plugin\views\display\Feed::attachTo() can then check if the plugins implement that interface:

Remaining tasks

User interface changes

API changes

Data model changes

Comments

jhedstrom created an issue. See original summary.

jhedstrom’s picture

Status: Active » Needs review
StatusFileSize
new3.86 KB
jhedstrom’s picture

dawehner’s picture

What about having a common interface for displays and styles?

jhedstrom’s picture

Issue tags: +Documentation

What about having a common interface for displays and styles?

Hmm, they currently take quite different arguments, so would that large of a refactor gain us anything? If for instance the style method had the display method's parameters, then each style plugin would need to dig into the view object to get the url, and title, etc.

Also adding the documentation tag as this impacts currently broken docblocks.

dawehner’s picture

  1. +++ b/core/modules/views/src/Plugin/views/style/AttachableStyleInterface.php
    @@ -0,0 +1,26 @@
    +  /**
    +   * This style is being attached to the given display.
    +   *
    +   * @param array $build
    +   *   The build render array.
    

    It would be nice to explain what attaching mean, so that the method is meant to change the $build to add some additional render element.

  2. +++ b/core/modules/views/src/Plugin/views/style/AttachableStyleInterface.php
    @@ -0,0 +1,26 @@
    +   * @param $display_id
    +   *   The display ID that this style is being attached to.
    ...
    +   * @param $title
    +   *   This display's title.
    

    Those two should be strings

dawehner’s picture

Status: Needs review » Needs work
jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new1.37 KB
new4.4 KB

re #6 I've made an attempt to clarify the docs here. It's a little awkward though based on how the current implementations modify both the $build array and the view object itself.

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.

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.

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.

jhedstrom’s picture

StatusFileSize
new4.25 KB

Re-roll of #8.

joachim’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/views/src/Plugin/views/style/AttachableStyleInterface.php
    @@ -0,0 +1,43 @@
    +   * This style is being attached to the given display.
    

    Reads a bit wrong. Not sure what to suggest instead though.

    'Allows the style to react when attached by a display'?

  2. +++ b/core/modules/views/src/Plugin/views/style/AttachableStyleInterface.php
    @@ -0,0 +1,43 @@
    +   *   `feed_icons` property of the view.
    

    Use single quotes, not backticks.

  3. +++ b/core/modules/views/src/Plugin/views/style/AttachableStyleInterface.php
    @@ -0,0 +1,43 @@
    +   * @code
    +   *   if ($display->hasPath()) {
    +   *     if (empty($this->preview)) {
    +   *       $build['#attached']['feed'][] = array($url, $title);
    +   *     }
    +   *   }
    +   *   else {
    +   *     $this->view->feedIcons[] = array(
    +   *       '#theme' => 'feed_icon',
    +   *       '#url' => $url,
    +   *       '#title' => $title,
    +   *     );
    +   *   }
    +   * @endcode
    

    This sample code needs some sort of explanation of what it's showing.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new1.22 KB
new4.41 KB

This should address #14.

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.

manuel garcia’s picture

Doing this makes sense to me, so +1. Also, patch still applies cleanly on 8.8.x so yay.

Took a look at the patch and it looks good, just a few minor things/nitpicks/questions:

  1. +++ b/core/modules/views/src/Plugin/views/style/Opml.php
    @@ -3,6 +3,7 @@
    +use Drupal\views\Plugin\views\style\AttachableStyleInterface;
    
    +++ b/core/modules/views/src/Plugin/views/style/Rss.php
    @@ -4,6 +4,7 @@
    +use Drupal\views\Plugin\views\style\AttachableStyleInterface;
    

    Since they are in the same namespace, are the use statements necessary?

  2. +++ b/core/modules/views/src/Plugin/views/style/AttachableStyleInterface.php
    @@ -0,0 +1,46 @@
    +   * @param array $build
    +   *   The build render array, passed by reference. Implementations can
    +   *   directly attach render elements here, or alternatively, manipulate the
    +   *   'feed_icons' property of the view.
    

    Should we be mentioning the feed icons on the interface?

  3. +++ b/core/modules/views/src/Plugin/views/style/AttachableStyleInterface.php
    @@ -0,0 +1,46 @@
    +   *   if ($display->hasPath()) {
    +   *     if (empty($this->preview)) {
    +   *       $build['#attached']['feed'][] = array($url, $title);
    +   *     }
    +   *   }
    +   *   else {
    +   *     $this->view->feedIcons[] = array(
    +   *       '#theme' => 'feed_icon',
    +   *       '#url' => $url,
    +   *       '#title' => $title,
    +   *     );
    +   *   }
    

    Let's use short array syntax in the sample code.

jhedstrom’s picture

StatusFileSize
new2.14 KB
new4 KB

This should address most of #17.

Should we be mentioning the feed icons on the interface?

I was a bit uncertain what you meant here, but I did notice that feed_icons isn't the actual view property, it's actually feedIcons (as demonstrated in the sample code block), so I've updated that comment.

manuel garcia’s picture

Thanks @jhedstrom changes look good. And actually after thinking a bit more, mentioning the feedIcons does make sense in there so this looks good to me. Got nothing else to complain about so RTBC++.

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.

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.

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.

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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

kunalgautam’s picture

Status: Needs work » Needs review
StatusFileSize
new3.71 KB

Re-roll patch for Drupal version 10.1.x

kunalgautam’s picture

StatusFileSize
new4.02 KB
_utsavsharma’s picture

StatusFileSize
new808 bytes
new4.04 KB

Fixed CCF for #29.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

LGTM.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This change will break quite a few modules. See https://git.drupalcode.org/search?group_id=2&repository_ref=&scope=blobs...

For example: https://git.drupalcode.org/project/xmlfeedviews/-/blob/1.0.x/src/Plugin/...

I think we need to check if the plugin implements the new interface and if not issue a deprecation but still call the method. And then in Drupal 11 do something different. I'm also not sure if silence is the correct option here. At the moment if the style plugin does not implement the attachTo() method you'll get a helpful error saying that it does not. With this patch you won't get any information as a developer that you should think about implementing this method.

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.

acbramley’s picture

Category: Bug report » Task
Issue tags: +Bug Smash Initiative

Based on our issue category definitions I don't think this should be considered a bug.

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.