Skip to content

Commit b42a6bf

Browse files
authored
Improve massive actions documentation with clearer structure and examples (#195)
1 parent a2422d1 commit b42a6bf

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

‎source/devapi/massiveactions.rst‎

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,48 +41,44 @@ To forbid this display for one field, you must define the key ``massiveaction``
4141
Specific massive actions
4242
^^^^^^^^^^^^^^^^^^^^^^^^
4343
44-
After the ``Update`` entry, we can declare additional specific massive actions for our current itemtype.
44+
If default massive actions are not sufficient for your needs, you can define your own massive actions.
45+
3 methods must be defined to achieve this.
46+
47+
1. declare the actions in ``getSpecificMassiveActions``
48+
2. display the form in ``showMassiveActionsSubForm``
49+
3. process in ``processMassiveActionsForOneItemtype``
4550
46-
First, we need declare in our class a ``getSpecificMassiveActions`` method containing our massive action definitions:
4751
4852
.. code-block:: php
4953
5054
<?php
5155
5256
...
5357
54-
function getSpecificMassiveActions($checkitem=NULL) {
55-
$actions = parent::getSpecificMassiveActions($checkitem);
56-
57-
// add a single massive action
58-
$class = __CLASS__;
59-
$action_key = "myaction_key";
60-
$action_label = "My new massive action";
61-
$actions[$class.MassiveAction::CLASS_ACTION_SEPARATOR.$action_key] = $action_label;
62-
63-
return $actions;
64-
}
58+
public function getSpecificMassiveActions($checkitem = null)
59+
{
60+
$actions = parent::getSpecificMassiveActions($checkitem);
6561
66-
A single declaration is defined by these parts:
62+
if (Session::haveRight(self::$rightname, UPDATE)) {
63+
$actions[self::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'update_visibility']
64+
= __('Visibility');
65+
}
6766
68-
- a ``classname``
69-
- a ``separator``: always ``MassiveAction::CLASS_ACTION_SEPARATOR``
70-
- a ``key``
71-
- and a ``label``
67+
return $actions;
68+
}
7269
73-
We can have multiple actions for the same class, and we may target different class from our current object.
7470
7571
.. _massiveactions_specific_subform:
7672
77-
Next, to display the form of our definitions, we need to declare a ``showMassiveActionsSubForm`` method:
73+
Next, implement ``showMassiveActionsSubForm`` to display the form :
7874
7975
.. code-block:: php
8076
8177
<?php
8278
8379
...
8480
85-
static function showMassiveActionsSubForm(MassiveAction $ma) {
81+
public static function showMassiveActionsSubForm(MassiveAction $ma) {
8682
switch ($ma->getAction()) {
8783
case 'myaction_key':
8884
echo __("fill the input");
@@ -97,7 +93,7 @@ Next, to display the form of our definitions, we need to declare a ``showMassive
9793
9894
.. _massiveactions_specific_process:
9995

100-
Finally, to process our definition, we need a ``processMassiveActionsForOneItemtype`` method:
96+
Finally, for processing implement ``processMassiveActionsForOneItemtype`` method:
10197

10298

10399
.. code-block:: php

0 commit comments

Comments
 (0)