Problem/Motivation

Currently, outside_in_contextual_links_view_alter() hardcodes a single contextual link as using offcanvas.
Any other links to be added will need the same logic.

Proposed resolution

Make it easier for contextual links to opt-in to being displayed in a dialog.
In #2784443: Move off-canvas functionality from Settings tray module into drupal.dialog.ajax library so that other modules can use it, make this available for all contextual links and all dialog/modal options.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#48 2820135-48.patch6.7 KBtedbow
#48 interdiff-2820135-46-48.txt2.56 KBtedbow
#46 allow_any_contextual-2820135-46.patch6.73 KByogeshmpawar
#46 interdiff-2820135-42-46.txt4.03 KByogeshmpawar
#42 allow_any_contextual-2820135-42.patch6.6 KByogeshmpawar
#42 interdiff-2820135-39-42.txt965 bytesyogeshmpawar
#39 2820135-39.patch6.6 KBrajeevk
#36 interdiff-34-36.txt562 bytestedbow
#36 2820135-36.patch6.08 KBtedbow
#34 2820135-34.patch6.09 KBtedbow
#34 interdiff-29-34.txt1.73 KBtedbow
#29 2820135-outside_in-29.patch6.13 KBtim.plunkett
#29 2820135-outside_in-29-interdiff.txt1.67 KBtim.plunkett
#28 interdiff-15-28.txt6.02 KBtedbow
#28 2820135-28.patch6.52 KBtedbow
#15 interdiff-2820135-12-15.txt1.17 KBtedbow
#15 2820135-15.patch6.11 KBtedbow
#12 interdiff-2820135-3-12.txt6.15 KBtedbow
#12 2820135-12.patch6.15 KBtedbow
#4 interdiff-2820135-3-4.txt4.99 KBtedbow
#4 2820135-4.patch7.64 KBtedbow
#3 2820135-offcanvas-3.patch5.9 KBtim.plunkett
#3 2820135-offcanvas-3-interdiff.txt5 KBtim.plunkett
#2 2820135-outside_in-2.patch2.36 KBtim.plunkett
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

Status: Active » Needs review
FileSize
2.36 KB
tim.plunkett’s picture

Always write test coverage! Found a bug, it were overwriting existing class attributes.

tedbow’s picture

Title: Allow any contextual link to opt-in to being displayed via offcanvas » Allow any contextual link to opt-in to being displayed via offcanvas or opt-in to Edit Mode
FileSize
7.64 KB
4.99 KB

@tim.plunkett thanks for this patch.

Looking at that patch I realized that outside.js is written so that any contextual link that used the offcanvas tray will always trigger edit mode. Long term we don't want this.

This patch separates this.

It also changes it so that a contextual link can designate it should trigger edit mode by

  options:
    outside-in-edit: true

This will take care of other options. It is also possible to just specify that it should be a dialog.

If a link just needs to open in the offcanvas then:

options:
    dialog-type: dialog
    dialog-renderer: offcanvas

Of course it could also specify 'modal' only.

I think in #2784443: Move off-canvas functionality from Settings tray module into drupal.dialog.ajax library so that other modules can use it
We should move the dialog-* options handling to contextual modal because it should be possible for contextual link to work with dialog system which they cannot now regardless anything in Setting Tray module.

Status: Needs review » Needs work

The last submitted patch, 4: 2820135-4.patch, failed testing.

tim.plunkett’s picture

  1. +++ b/core/modules/outside_in/js/outside_in.js
    @@ -7,7 +7,7 @@
    -  var blockConfigureSelector = '[data-dialog-renderer="offcanvas"]';
    +  var blockConfigureSelector = '[data-outside-in-edit]';
    

    I think this is out of scope.

  2. +++ b/core/modules/outside_in/outside_in.links.contextual.yml
    @@ -3,5 +3,4 @@ outside_in.block_configure:
    -    dialog-type: dialog
    -    dialog-renderer: offcanvas
    
    +++ b/core/modules/outside_in/outside_in.module
    @@ -30,20 +30,30 @@ function outside_in_help($route_name, RouteMatchInterface $route_match) {
    +      elseif (!empty($item['localized_options']['dialog-type'])) {
    +        // @todo Move to \Drupal\contextual\Element\ContextualLinks::preRenderLinks()
    +        // in https://www.drupal.org/node/2784443.
    +        $element['#links'][$class]['attributes']['class'][] = 'use-ajax';
    +        $element['#links'][$class]['attributes']['data-dialog-type'] = $item['localized_options']['dialog-type'];
    +        if (!empty($item['localized_options']['dialog-renderer'])) {
    +          $element['#links'][$class]['attributes']['data-dialog-renderer'] = $item['localized_options']['dialog-renderer'];
    +          if ($element['#links'][$class]['attributes']['data-dialog-renderer'] == 'offcanvas') {
    +            $add_library = TRUE;
    +          }
    +        }
           }
    

    Considering that we're still keeping the code I proposed adding anyway, why not do this first as above, and make the outside-in-edit bit a new issue?

tedbow’s picture

Title: Allow any contextual link to opt-in to being displayed via offcanvas or opt-in to Edit Mode » Allow any contextual link to opt-in to being displayed via offcanvas
Status: Needs work » Needs review

I doing my interdiff against #3 because I got rid of most of my changes in #4.
RE: #6

I think this is out of scope.

I changed the title/scope of this issue back to "Allow any contextual link to opt-in to being displayed via offcanvas"
Without of the change to blockConfigureSelector it actually won't be possible to opt in to offcanvas without also triggering Settings Tray module Edit Mode.
Since we are trying to keep OffCanvas dialog and the Settings Tray module separate we need this to keep in scope with what the issue is trying to do. It was never an issue or noticed before because only this modules links were using offcanvas.

tedbow’s picture

tedbow’s picture

tedbow’s picture

Status: Postponed » Needs work
tedbow’s picture

Ok here is patch.

Interdiff from #3.

tedbow’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

+++ b/core/modules/outside_in/outside_in.module
@@ -30,17 +31,28 @@ function outside_in_help($route_name, RouteMatchInterface $route_match) {
+ * @todo Move to \Drupal\contextual\Element\ContextualLinks::preRenderLinks() in
++  *   https://www.drupal.org/node/2784443.
...
+    if (isset($element['#links'][$class]) && !empty($item['localized_options']['dialog-type'])) {
...
+  // This section should NOT be moved to
+  // \Drupal\contextual\Element\ContextualLinks::preRenderLinks().
   if (isset($element['#links']['outside-inblock-configure'])) {

I would move the @todo inline so that it is more clear which part is being removed.

tedbow’s picture

@tim.plunkett moved comments.

webchick’s picture

Category: Task » Feature request

Discussing this with the team, it seems like this is a nice-to-have and so far we haven't seen any actual use cases for it. Switching to feature request.

webchick’s picture

Category: Feature request » Task

Oops. :) Actually, this is pretty important from the standpoint of standardizing on ways for modules (e.g. Field Layout) to interact with the Settings Tray, however, the existing dialog system has the same limitations, so it remains a normal task.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

I wrote the initial PoC and tests, but it's been @tedbow's work since then, so I feel comfortable marking this as RTBC.

Wim Leers’s picture

+++ b/core/modules/outside_in/outside_in.module
@@ -29,18 +30,27 @@ function outside_in_help($route_name, RouteMatchInterface $route_match) {
+  $add_library = FALSE;

Nit: s/add/attach/

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2820135-15.patch, failed testing.

tedbow’s picture

Status: Needs work » Reviewed & tested by the community

Setting back to RTBC because it was DrupalCI error

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2820135-15.patch, failed testing.

tedbow’s picture

Status: Needs work » Reviewed & tested by the community

#22 was random test failure and now passing

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2820135-15.patch, failed testing.

tedbow’s picture

Status: Needs work » Reviewed & tested by the community

Random failure back to RTBC, rinse and repeat ;)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/outside_in/tests/src/Unit/ContextualLinksViewAlterTest.php
    @@ -0,0 +1,143 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public static $modules = ['outside_in'];
    ...
    +    require_once $this->root . '/core/modules/outside_in/outside_in.module';
    

    This shouldn't do anything. Since this is a unit test. However as we're loading code - let's make this a kernel test and be done. Then we don't need to worry about including code and we don't need to worry about other tests and code inclusion issues.

  2. +++ b/core/modules/outside_in/tests/src/Unit/ContextualLinksViewAlterTest.php
    @@ -0,0 +1,143 @@
    +  public function testValidDialogOptions() {
    ...
    +  public function testNoDialogOptions() {
    

    This looks like we could use an @dataProvider here instead. Which would make adding future test cases simpler.

tim.plunkett’s picture

If we make it a kernel test, then we can't use @covers for a global function. It seems like the test cleans up after itself, and \Drupal\Tests\Listeners\DrupalStandardsListener::checkValidCoversForTest() runs late enough that function_exist() returns FALSE again.

So that's a toss-up.

But +1 to using @dataProvider

tedbow’s picture

Status: Needs work » Needs review
FileSize
6.52 KB
6.02 KB

Here is patch that leaves it as a Unit test but uses a dataprovider

tim.plunkett’s picture

Prefer using a keyed array for a dataProvider, makes it easier to debug (it puts the string into the output if it fails!).
Interdiff is against #15

Is the require_once that problematic for a unit test?

tedbow’s picture

Status: Needs review » Reviewed & tested by the community

Setting back to RTBC. Thanks @alexpott's concerns have been addressed.

webchick’s picture

Assigned: Unassigned » alexpott

#27 sounds reasonable to me, but kicking back to @alexpott to make sure he thinks so, too. :)

Reviewed the patch and nothing stuck out to me though.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/outside_in/tests/src/Unit/ContextualLinksViewAlterTest.php
@@ -0,0 +1,147 @@
+    require_once $this->root . '/core/modules/outside_in/outside_in.module';

This affects the test environment of every single unit test - we shouldn't be adding includes in unit tests. The @covers reason definitely is not a good enough reason to break this. If anything it means we need to file a bug against the @covers standards checker (which to be honest I'm not a huge fan of).

alexpott’s picture

Assigned: alexpott » Unassigned
tedbow’s picture

Status: Needs work » Needs review
FileSize
1.73 KB
6.09 KB

Ok this changes it to a Kernel test to get of the "required_once"

Status: Needs review » Needs work

The last submitted patch, 34: 2820135-34.patch, failed testing.

tedbow’s picture

Status: Needs work » Needs review
FileSize
6.08 KB
562 bytes

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.

tedbow’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Needs reroll because of #2862625: Rename offcanvas to two words in code and comments. and other recent commits

rajeevk’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
6.6 KB

Attaching patch for re-roll.

Resolved conflict in core/module/outside_in/outside_in.module found in rebasing 8.4.x on last passed version.

Status: Needs review » Needs work

The last submitted patch, 39: 2820135-39.patch, failed testing.

tedbow’s picture

+++ b/core/modules/outside_in/outside_in.links.contextual.yml
@@ -2,3 +2,6 @@ outside_in.block_configure:
+    dialog-renderer: offcanvas

Think this will have to be "off_canvas" not "offcanvas"

Actually I think all the occurrences of "offcanvas" in the patch should be replaced with "off_canvas". They are deal with the renderer.

See #2862625: Rename offcanvas to two words in code and comments.

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
965 bytes
6.6 KB

Changes made as per comment #41.

Status: Needs review » Needs work

The last submitted patch, 42: allow_any_contextual-2820135-42.patch, failed testing.

tedbow’s picture

@Yogesh Pawar thanks for the patch.

there are a couple other occurrences of ''offcanvas''

Also couple other things I didn't catch before.

  1. +++ b/core/modules/outside_in/tests/src/Kernel/ContextualLinksViewAlterTest.php
    @@ -0,0 +1,137 @@
    +          'dialog-renderer' => 'offcanvas',
    

    Should be off_canvas

  2. +++ b/core/modules/outside_in/tests/src/Kernel/ContextualLinksViewAlterTest.php
    @@ -0,0 +1,137 @@
    +            'data-dialog-renderer' => 'offcanvas',
    

    Should be off_canvas

  3. +++ b/core/modules/outside_in/outside_in.module
    @@ -29,27 +30,27 @@ function outside_in_help($route_name, RouteMatchInterface $route_match) {
    -  if (isset($element['#links']['outside-inblock-configure'])) {
    -    // Place outside_in link first.
    -    $outside_in_link = $element['#links']['outside-inblock-configure'];
    -    unset($element['#links']['outside-inblock-configure']);
    -    $element['#links'] = ['outside-inblock-configure' => $outside_in_link] + $element['#links'];
    

    This logic cannot be removed. It causes a test failure.

    See \Drupal\Tests\outside_in\FunctionalJavascript\OutsideInBlockFormTest::testBlocks

    $this->assertEquals('Quick edit', $link->getText(), "'Quick edit' is the first contextual link for the block.");

  4. +++ b/core/modules/outside_in/outside_in.module
    @@ -29,27 +30,27 @@ function outside_in_help($route_name, RouteMatchInterface $route_match) {
    -    // If this is content block change title to avoid duplicate "Quick Edit".
    -    if (isset($element['#links']['block-contentblock-edit'])) {
    -      $element['#links']['outside-inblock-configure']['title'] = t('Quick edit settings');
    

    This logic cannot be removed:

    See \Drupal\Tests\outside_in\FunctionalJavascript\OutsideInBlockFormTest::testCustomBlockLinks

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
FileSize
4.03 KB
6.73 KB

Thanks @tedbow, for the suggestions. Added updated patch with interdiff, hope so test will not fail this time.

Status: Needs review » Needs work

The last submitted patch, 46: allow_any_contextual-2820135-46.patch, failed testing.

tedbow’s picture

Status: Needs work » Needs review
FileSize
2.56 KB
6.7 KB

@Yogesh Pawar hopefully this will fix it.

I just have to move the new code outside of the if statement it was within.

jian he’s picture

Status: Needs review » Reviewed & tested by the community

Setting back to RTBC. I have write some contextual links to test the patch #48 manually, it works great.

yogeshmpawar’s picture

any update on this issue ? it's it RTBC since last 2 weeks.

tedbow’s picture

Status: Reviewed & tested by the community » Closed (outdated)

I don't think we will need special logic for this once #2892942: Contextual links support options but not use them to generate links is supported.

That issue was committed and then reverted because it is needs test. If you want this functionality then working on that issue will get it.

I briefly did #2893978: Use newly supported 'options' in contextual links in Settings Tray contextual links before the revert but this will show you how it works.

tedbow’s picture

Component: outside_in.module » settings_tray.module

Changing to new settings_tray.module component. @drpal thanks for script help! :)