Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
221
Merge Requests
221
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
f946527e
Commit
f946527e
authored
Jan 21, 2013
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1851082
by tim.plunkett: Add a base bulk form handler class, remove it from Actions module.
parent
b3f18a65
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
77 deletions
+128
-77
core/modules/action/action.views.inc
core/modules/action/action.views.inc
+5
-1
core/modules/action/lib/Drupal/action/Plugin/views/field/BulkForm.php
.../action/lib/Drupal/action/Plugin/views/field/BulkForm.php
+7
-75
core/modules/action/tests/action_bulk_test/config/views.view.test_bulk_form.yml
...sts/action_bulk_test/config/views.view.test_bulk_form.yml
+1
-1
core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php
...tem/lib/Drupal/system/Plugin/views/field/BulkFormBase.php
+115
-0
No files found.
core/modules/action/action.views.inc
View file @
f946527e
...
...
@@ -14,7 +14,11 @@
* the alter hook doesn't load the *.views.inc automatically.
*/
function
action_views_data
()
{
$data
[
'views'
][
'action_bulk_form'
]
=
array
(
$data
[
'action'
][
'table'
][
'group'
]
=
t
(
'Action'
);
$data
[
'action'
][
'table'
][
'join'
]
=
array
(
'#global'
=>
array
(),
);
$data
[
'action'
][
'action_bulk_form'
]
=
array
(
'title'
=>
t
(
'Bulk update'
),
'help'
=>
t
(
'Allows users to apply an action to one or more items.'
),
'field'
=>
array
(
...
...
core/modules/action/lib/Drupal/action/Plugin/views/field/BulkForm.php
View file @
f946527e
...
...
@@ -8,61 +8,22 @@
namespace
Drupal\action\Plugin\views\field
;
use
Drupal\Core\Annotation\Plugin
;
use
Drupal\
views\Plugin\views\field\FieldPlugin
Base
;
use
Drupal\
system\Plugin\views\field\BulkForm
Base
;
/**
* Defines a
simple
bulk operation form element.
* Defines a
actions-based
bulk operation form element.
*
* @Plugin(
* id = "action_bulk_form",
* module = "action"
* )
*/
class
BulkForm
extends
FieldPlugin
Base
{
class
BulkForm
extends
BulkForm
Base
{
/**
*
Overrides \Drupal\views\Plugin\views\Plugin\field\FieldPluginBase::render
().
*
Implements \Drupal\system\Plugin\views\field\BulkFormBase::getBulkOptions
().
*/
public
function
render
(
$values
)
{
return
'<!--form-item-'
.
$this
->
options
[
'id'
]
.
'--'
.
$this
->
view
->
row_index
.
'-->'
;
}
/**
* Overrides \Drupal\views\Plugin\views\Plugin\field\FieldPluginBase::pre_render().
*/
public
function
pre_render
(
&
$values
)
{
parent
::
pre_render
(
$values
);
// If the view is using a table style, provide a placeholder for a
// "select all" checkbox.
if
(
!
empty
(
$this
->
view
->
style_plugin
)
&&
$this
->
view
->
style_plugin
instanceof
\
Drupal\views\Plugin\views\style\Table
)
{
// Add the tableselect css classes.
$this
->
options
[
'element_label_class'
]
.
=
'select-all'
;
// Hide the actual label of the field on the table header.
$this
->
options
[
'label'
]
=
''
;
}
}
/**
* Implements \Drupal\views\Plugin\views\Plugin\field\FieldPluginBase::views_form().
*/
public
function
views_form
(
&
$form
,
&
$form_state
)
{
// Add the tableselect javascript.
$form
[
'#attached'
][
'library'
][]
=
array
(
'system'
,
'drupal.tableselect'
);
// Render checkboxes for all rows.
$form
[
$this
->
options
[
'id'
]][
'#tree'
]
=
TRUE
;
foreach
(
$this
->
view
->
result
as
$row_index
=>
$row
)
{
$form
[
$this
->
options
[
'id'
]][
$row_index
]
=
array
(
'#type'
=>
'checkbox'
,
// We are not able to determine a main "title" for each row, so we can
// only output a generic label.
'#title'
=>
t
(
'Update this item'
),
'#title_display'
=>
'invisible'
,
'#default_value'
=>
!
empty
(
$form_state
[
'values'
][
$this
->
options
[
'id'
]][
$row_index
])
?
1
:
NULL
,
);
}
protected
function
getBulkOptions
()
{
// Get all available actions.
$actions
=
action_get_all_actions
();
$entity_type
=
$this
->
getEntityType
();
...
...
@@ -70,36 +31,13 @@ public function views_form(&$form, &$form_state) {
$actions
=
array_filter
(
$actions
,
function
(
$action
)
use
(
$entity_type
)
{
return
$action
[
'type'
]
==
$entity_type
&&
empty
(
$action
[
'configurable'
]);
});
$options
=
array_map
(
function
(
$action
)
{
return
array_map
(
function
(
$action
)
{
return
$action
[
'label'
];
},
$actions
);
// Replace the form submit button label.
$form
[
'actions'
][
'submit'
][
'#value'
]
=
t
(
'Apply'
);
// Ensure a consistent container for filters/operations in the view header.
$form
[
'header'
]
=
array
(
'#type'
=>
'container'
,
'#weight'
=>
-
100
,
);
// Build the bulk operations action widget for the header.
// Allow themes to apply .container-inline on this separate container.
$form
[
'header'
][
$this
->
options
[
'id'
]]
=
array
(
'#type'
=>
'container'
,
);
$form
[
'header'
][
$this
->
options
[
'id'
]][
'action'
]
=
array
(
'#type'
=>
'select'
,
'#title'
=>
t
(
'With selection'
),
'#options'
=>
$options
,
);
// Duplicate the form actions into the action container in the header.
$form
[
'header'
][
$this
->
options
[
'id'
]][
'actions'
]
=
$form
[
'actions'
];
}
/**
* Implements \Drupal\
views\Plugin\views\Plugin\field\FieldPlugin
Base::views_form_submit().
* Implements \Drupal\
system\Plugin\views\field\BulkForm
Base::views_form_submit().
*/
public
function
views_form_submit
(
&
$form
,
&
$form_state
)
{
if
(
$form_state
[
'step'
]
==
'views_form_views_form'
)
{
...
...
@@ -127,10 +65,4 @@ public function views_form_submit(&$form, &$form_state) {
}
}
/**
* Overrides \Drupal\views\Plugin\views\Plugin\field\FieldPluginBase::query().
*/
public
function
query
()
{
}
}
core/modules/action/tests/action_bulk_test/config/views.view.test_bulk_form.yml
View file @
f946527e
...
...
@@ -74,7 +74,7 @@ display:
link_to_node
:
'
1'
bulk_form
:
id
:
action_bulk_form
table
:
views
table
:
action
field
:
action_bulk_form
relationship
:
none
group_type
:
group
...
...
core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php
0 → 100644
View file @
f946527e
<?php
/**
* @file
* Contains \Drupal\system\Plugin\views\field\BulkFormBase.
*/
namespace
Drupal\system\Plugin\views\field
;
use
Drupal\Core\Annotation\Plugin
;
use
Drupal\views\Plugin\views\field\FieldPluginBase
;
use
Drupal\views\Plugin\views\style\Table
;
/**
* Defines a generic bulk operation form element.
*/
abstract
class
BulkFormBase
extends
FieldPluginBase
{
/**
* Overrides \Drupal\views\Plugin\views\Plugin\field\FieldPluginBase::render().
*/
public
function
render
(
$values
)
{
return
'<!--form-item-'
.
$this
->
options
[
'id'
]
.
'--'
.
$this
->
view
->
row_index
.
'-->'
;
}
/**
* Overrides \Drupal\views\Plugin\views\Plugin\field\FieldPluginBase::pre_render().
*/
public
function
pre_render
(
&
$values
)
{
parent
::
pre_render
(
$values
);
// If the view is using a table style, provide a placeholder for a
// "select all" checkbox.
if
(
!
empty
(
$this
->
view
->
style_plugin
)
&&
$this
->
view
->
style_plugin
instanceof
Table
)
{
// Add the tableselect css classes.
$this
->
options
[
'element_label_class'
]
.
=
'select-all'
;
// Hide the actual label of the field on the table header.
$this
->
options
[
'label'
]
=
''
;
}
}
/**
* Form constructor for the bulk form.
*
* @param array $form
* An associative array containing the structure of the form.
* @param array $form_state
* An associative array containing the current state of the form.
*/
public
function
views_form
(
&
$form
,
&
$form_state
)
{
// Add the tableselect javascript.
$form
[
'#attached'
][
'library'
][]
=
array
(
'system'
,
'drupal.tableselect'
);
// Render checkboxes for all rows.
$form
[
$this
->
options
[
'id'
]][
'#tree'
]
=
TRUE
;
foreach
(
$this
->
view
->
result
as
$row_index
=>
$row
)
{
$form
[
$this
->
options
[
'id'
]][
$row_index
]
=
array
(
'#type'
=>
'checkbox'
,
// We are not able to determine a main "title" for each row, so we can
// only output a generic label.
'#title'
=>
t
(
'Update this item'
),
'#title_display'
=>
'invisible'
,
'#default_value'
=>
!
empty
(
$form_state
[
'values'
][
$this
->
options
[
'id'
]][
$row_index
])
?
1
:
NULL
,
);
}
// Replace the form submit button label.
$form
[
'actions'
][
'submit'
][
'#value'
]
=
t
(
'Apply'
);
// Ensure a consistent container for filters/operations in the view header.
$form
[
'header'
]
=
array
(
'#type'
=>
'container'
,
'#weight'
=>
-
100
,
);
// Build the bulk operations action widget for the header.
// Allow themes to apply .container-inline on this separate container.
$form
[
'header'
][
$this
->
options
[
'id'
]]
=
array
(
'#type'
=>
'container'
,
);
$form
[
'header'
][
$this
->
options
[
'id'
]][
'action'
]
=
array
(
'#type'
=>
'select'
,
'#title'
=>
t
(
'With selection'
),
'#options'
=>
$this
->
getBulkOptions
(),
);
// Duplicate the form actions into the action container in the header.
$form
[
'header'
][
$this
->
options
[
'id'
]][
'actions'
]
=
$form
[
'actions'
];
}
/**
* Returns the available operations for this form.
*
* @return array
* An associative array of operations, suitable for a select element.
*/
abstract
protected
function
getBulkOptions
();
/**
* Submit handler for the bulk form.
*
* @param array $form
* An associative array containing the structure of the form.
* @param array $form_state
* An associative array containing the current state of the form.
*/
abstract
public
function
views_form_submit
(
&
$form
,
&
$form_state
);
/**
* Overrides \Drupal\views\Plugin\views\Plugin\field\FieldPluginBase::query().
*/
public
function
query
()
{
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment