Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Sub-issue for meta issue #1880976: [meta] Port examples (including submodules) to D9.4+
Problem/Motivation
We need to demonstrate adding contextual links to entities.
Proposed resolution
Let's add a new module, called contextual_link_example, which implements edit, view, and delete contextual links to the content_entity_example module.
This module will have examples:content_entity_example as a dependency.
Comment | File | Size | Author |
---|---|---|---|
#47 | interdiff.txt | 3.76 KB | Mile23 |
#47 | 2102647_46.patch | 26.69 KB | Mile23 |
#45 | interdiff-43-45.txt | 969 bytes | navneet0693 |
#45 | 2102647-45.patch | 23.99 KB | navneet0693 |
| |||
#43 | interdiff-2102647-41-43.txt | 3.53 KB | martin107 |
Comments
Comment #1
a_thakur CreditAttribution: a_thakur commentedStarted working on this.
Comment #2
marvil07 CreditAttribution: marvil07 commentedJust cleaning. If there is a patch please add it.
Comment #3
icanblink CreditAttribution: icanblink commentedLooking into it.
Comment #4
icanblink CreditAttribution: icanblink commentedAdded the patch for porting contextual links example.
Comment #5
icanblink CreditAttribution: icanblink commentedComment #7
Lal_I've rerolled the patch.
Comment #8
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedAdded tests and did a significant amount changes to patch #7, added theme functions, removed unwanted code, corrected code and now it's fully working !
Comment #10
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #12
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #14
Mile23Thanks!
Here's some review. More to come on the test.
Should require contextual.
Why do we have a storage class if it's just a stub implementation?
Should not require contextual here.
Comment #15
Mile23Can't typehint int for PHP 5.5.
This block never shows up in the block admin page.
As for the tests.... Based on
Drupal\Tests\contextual\FunctionalJavascript\ContextualLinksTest
, it seems we'll need to inherit fromJavascriptTestBase
to get the click that opens the contextual menu.That needs some local dev environment setup: https://www.drupal.org/docs/8/phpunit/phpunit-javascript-testing-tutorial
Comment #16
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedHey @Mile23, thank you very much your review.
Yes, Storage class is just a stub implementation.
I will work upon for other changes.
Comment #17
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commented@Mile23
This does show up. You will have to place it using Block Interface UI.
Comment #18
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #19
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #21
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedI am doing something wrong here,
@Mil23, after observing html results of tests, I observed that contextual links doesn't render on minimal profile . I having less knowledge on how to proceed in this scenario. How can we proceed with tests ?
Comment #22
Mile23See #15. Contextual menus are javascript-based, so we have to use functional javascript tests. Here's a test from core: http://cgit.drupalcode.org/drupal/tree/core/modules/contextual/tests/src...
Comment #23
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedFirst attempt for javascript functional test.
Comment #25
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #27
Mile23Are you sure this class exists?
Comment #28
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commented@Mile23 yes! I am attaching a screenshot of HTML output of JS test.
Comment #29
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedEverything needs to be perfect for tests to pass !
Comment #30
martin107 CreditAttribution: martin107 as a volunteer commentedA minor adjustment
I have dropped t() in favour of $this->t().
Comment #31
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedThank you @martin. Oops! My bad. Updating it to examples:examples
Comment #32
Mile23Coming along...
Needs @defgroup, and an explanation of what this module does and how it does it.
We should have some text on this page to explain what's being accomplished, generally how it works, and what to look at next for specifics.
I doubt these ids will always be the same. We should just load all the CLEEntity objects that are available.
Should be @see and not have a period at the end.
Is there not a generic entity base implementation we can use instead?
We don't use @package.
Comment #33
Mile23Comment #34
Lal_working on it
Comment #35
Lal_Still stuck with issue #5 and #3
Comment #36
Lal_Comment #38
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedNot a correct way of doing this.
Use DescriptionTemplateTrait and $this->description to add in build array.
Please do not remove this.
Did you change something in tests ?
Comment #39
Lal_Comment #41
Lal_Comment #42
Lal_Need to fix few more issues
Comment #43
martin107 CreditAttribution: martin107 as a volunteer commentedJust fixed a few coding standard nits while reading along.
Comment #44
Mile23Comment #45
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #46
Mile23OK, so we have way too much stuff here just to implement an entity that we can't edit.
The storage class doesn't actually do anything.
This patch adds a test that demonstrates that we can't save our new entity.
So let's rescope a bit.
Let's add a contextual link implementation to the content entity example.
This means we can get rid of all the entity implementation details from this patch, and worry instead about adding contextual links.
Comment #47
Mile23Hah. Forgot the patch.
Comment #49
valthebaldMoving to new examples meta