Problem/Motivation
The ViewsFormMainForm class let's a chance to views area plugin to extend the view form. The code involved is the following:
// Give the area handlers a chance to extend the form.
$area_handlers = array_merge(array_values($view->header), array_values($view->footer));
$empty = empty($view->result);
foreach ($area_handlers as $area) {
if (method_exists($area, 'viewsForm') && !$area->viewsFormEmpty($empty)) {
$area->viewsForm($form, $form_state);
}
}
But as a DX, this is not possible to know since viewsForm() and viewsFormEmpty() methods are not defined in any interface.
The purpose of this issue is to give a developper that needs to override view form a chance to know.
NOTE: viewsForm is used in core in BulkForm view field type (ie extending FieldPluginBase). But is never used in a AreaPluginBase. This means that there is even no code exemple in core to discover the existence of viewsFormEmpty().
Proposed resolution
I can see two ways to do it without BC break:
- Define it in existing interface (like ViewsHandlerInterface) and implement a default empty method in AreaPluginBase an. FieldPlhttps://www.drupal.org/sites/all/modules/bueditor/icons/x1.pnguginBase.
Advantage: methods are in the current interface. The base classes implements empty method thus no BC.
Inconvenient: since defined, the methods will actually be called everytime, despite emDty. - Define the two methods in a new Interface to be implemented
Advantage: methods will no longer need empty implementation
Inconvenient: if no class in core implements it, will it be more discoverable by DX ?
Comments
Comment #2
dawehnerWell I think in core we could totally switch over to the new interface.
In case something has the method, but doesn't implement the interface we should even some
@trigger_error(E_USER_DEPRECATED)
error, so people can switch over.Given that I think version 2 is both more safe but also actually better conceptually, if we would start from scratch again.
Comment #3
anavarreComment #4
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedSo going with second method, it only take a new interface with the two method definition. Nothing more.
How can DX finds out easily about it ?
Also what about the consistency between AreaPluginBase and FieldPluginBase: the second just have viewsForm() to define while the first needs two methods. Should we have both a AreaPluginFormInterface and a FieldPluginFormInterface to be define ?
Comment #5
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedJust changing issue title for more clarity.