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
We can now document an array of objects of a certain type. Let's use that in views in as many places as possible.
...
/**
* @var \Drupal\foo\baz\Ba[]
*/
protected $bas;
...
Proposed resolution
Places where we can use it:
\Drupal\views\ViewExecutable::$old_views
\Drupal\views\ViewExecutable::$parent_views
\Drupal\views\ViewExecutable::$field
\Drupal\views\ViewExecutable::$argument
\Drupal\views\ViewExecutable::$sort
\Drupal\views\ViewExecutable::$filter
\Drupal\views\ViewExecutable::$relationship
\Drupal\views\ViewExecutable::$header
\Drupal\views\ViewExecutable::$footer
\Drupal\views\ViewExecutable::$empty
\Drupal\views\Plugin\views\display\DisplayPluginBase::$handlers
\Drupal\views\Plugin\views\display\DisplayPluginBase::$plugins
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#11 | drupal-2356183-11.patch | 3.63 KB | michaellenahan |
#8 | drupal-2356183-6.patch | 3.61 KB | michaellenahan |
#5 | drupal-2356183-5.patch | 3.6 KB | michaellenahan |
#3 | drupal-2356183-3.patch | 2.87 KB | michaellenahan |
Comments
Comment #1
michaellenahan CreditAttribution: michaellenahan commentedComment #2
michaellenahan CreditAttribution: michaellenahan commentedTo provide better type-checking in IDEs, we can explicitly say what kind of array it is in the comment.
Here's an example, $old_view is an array of ViewExecutable objects.
Comment #3
michaellenahan CreditAttribution: michaellenahan commentedHere's a patch, but I wasn't sure what to do with:
\Drupal\views\Plugin\views\display\DisplayPluginBase::$handlers
\Drupal\views\Plugin\views\display\DisplayPluginBase::$plugins
Comment #4
dawehnerReally cool!
DisplayPluginBase::$handlers
could be\Drupal\views\Plugin\views\HandlerBase[]
and
\Drupal\views\Plugin\views\PluginBase[]
Comment #5
michaellenahan CreditAttribution: michaellenahan commentedOK. Makes sense :)
Comment #6
michaellenahan CreditAttribution: michaellenahan commentedComment #7
michaellenahan CreditAttribution: michaellenahan commentedComment #8
michaellenahan CreditAttribution: michaellenahan commentedForgot a backslash before \Drupal in some places, for example:
\Drupal\views\Plugin\views\area\AreaPluginBase[]
Comment #9
dawehnerAwesome michael.
See you a bit more in the issue queue, if you like!
Comment #10
jhodgdonThis is mostly great!
One question though... Normally rather than using ClassName[] we would want to have InterfaceName[] for the variable type.
For instance, I think instead of \Drupal\views\Plugin\views\PluginBase[] it should maybe be ViewsPluginInterface?
See https://www.drupal.org/node/1354#types
"Use interface names if possible, or the most general possible class, in place of a specific class."
So, ... not sure if these are all the most general class or interface?
Comment #11
michaellenahan CreditAttribution: michaellenahan commentedThe only interfaces could find were: ViewsHandlerInterface, ViewsPluginInterface.
Otherwise, I *think* the classes are as general as they get.
Comment #12
dawehnerYeah this is pretty much it.
@jhodgon
Interfaces makes sense if you have a design which is decoupled, but in views this is not that fine yet.
Comment #13
alexpottCommitted 999b26c and pushed to 8.0.x. Thanks!
Comment #15
jhodgdonYeah, great! I just wanted to make sure that where we *have* interfaces, we use them in the docs. +1 on the RTBC and commit. :) Thanks!
Comment #16
dawehner@michaellenahan
In case you want to continue to help a bit, #2359703: Remove public visibility from pager variables on the ViewExecutable is a bit more advanced issue, in order to get you more addicted ;)