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.
Problem/Motivation
The 'Select list' add mode can render an option list with a single item when a single type is allowed in its field configuration. Since there are no options to select, this interface element can be hidden instead.
This matches the implementation in D7 added in #2364003: Hide bundle selection on field widget if only one bundle is allowed
Proposed resolution
Hide type selection in 'Select list' add mode when only one type is allowed.
Remaining tasks
- Write a patch
- Review
- Commit
User interface changes
The 'Select list' add mode hides the option list when a single type is allowed in its field configuration.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#8 | 3072638-8.patch | 3.21 KB | idebr |
| |||
#8 | 3072638-8-test-only.patch | 2.04 KB | idebr |
#8 | interdiff-5-8.txt | 4.1 KB | idebr |
#5 | 3072638-5-test-only.patch | 2.06 KB | idebr |
Comments
Comment #2
idebr CreditAttribution: idebr at ezCompany commentedAttached patch hides the type selection in 'Select list' add mode when only one type is allowed.
Comment #4
Berdir#type value might make more sense here, hidden is sent to the browser and could be changed.
Is the use case that the allowed paragraphs might vary per user?
If it's always just one then you can also use a different add mode like dropbutton, that will then just have a single button named "Add X"
Comment #5
idebr CreditAttribution: idebr at ezCompany commented#4.1 I did not know
'#type' => 'value'
was a thing, but that is a better fit for this code indeed. The primary goal is to reduce interface clutter.#4.2 To provide some context: the page requires structured data in different fields, but using the same paragraph type. A live page is available at https://www.uu.nl/en/newton-hall
I have taken screenshots of the different form configurations:
#1 Add mode 'Select list', implementation in 8.x-1.x HEAD:
#2 Add mode 'Buttons'
#3 Add mode 'Select list': with patch #5
Option #3 provides context to the buttons and hides the generic Paragraph type label from the editor.
Comment #7
BerdirOk, reusing the same paragraph type in different contexts is an interesting use case.
Would be nice to get the test moved to \Drupal\Tests\paragraphs\Functional\ParagraphsExperimentalWidgetButtonsTest, one thing less we have to convert to phpunit later on. Hopefully the tests shouldn't be too different.
Comment #8
idebr CreditAttribution: idebr at ezCompany commented#7 I moved the test to \Drupal\Tests\paragraphs\Functional\ParagraphsExperimentalWidgetButtonsTest. Both are based on PHPUnit BrowserTestBase, so the code itself is identical to #5.
Comment #11
BerdirI was sure the test was in a simpletest-based test, sorry.
Thanks, committed.