Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
9cf15532
Verified
Commit
9cf15532
authored
5 years ago
by
Lee Rowlands
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3084043
by phenaproxima, alexpott: Convert media_library_update_8703() to a post-update hook
parent
7af2d3d3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/media_library/media_library.install
+4
-210
4 additions, 210 deletions
core/modules/media_library/media_library.install
core/modules/media_library/media_library.post_update.php
+222
-0
222 additions, 0 deletions
core/modules/media_library/media_library.post_update.php
with
226 additions
and
210 deletions
core/modules/media_library/media_library.install
+
4
−
210
View file @
9cf15532
...
...
@@ -220,216 +220,10 @@ function media_library_update_8702() {
}
/**
*
Add edit and delete button to media library view page display
.
*
This update has been removed and will not run
.
*/
function
media_library_update_8703
()
{
$view
=
\Drupal
::
configFactory
()
->
getEditable
(
'views.view.media_library'
);
if
(
!
$view
->
isNew
()
&&
$view
->
get
(
'display.page'
))
{
// Fetch the fields from the page display, if the fields are not yet
// overridden, get the fields from the default display.
$fields
=
$view
->
get
(
'display.page.display_options.fields'
);
if
(
!
$fields
)
{
$fields
=
$view
->
get
(
'display.default.display_options.fields'
);
// Override the fields for the page display.
$view
->
set
(
'display.page.display_options.defaults.fields'
,
FALSE
);
}
// Check if the name field already exists and add if it doesn't.
if
(
!
isset
(
$fields
[
'name'
]))
{
$fields
[
'name'
]
=
[
'id'
=>
'name'
,
'table'
=>
'media_field_data'
,
'field'
=>
'name'
,
'relationship'
=>
'none'
,
'group_type'
=>
'group'
,
'admin_label'
=>
''
,
'label'
=>
''
,
'exclude'
=>
TRUE
,
'alter'
=>
[
'alter_text'
=>
FALSE
,
'text'
=>
''
,
'make_link'
=>
FALSE
,
'path'
=>
''
,
'absolute'
=>
FALSE
,
'external'
=>
FALSE
,
'replace_spaces'
=>
FALSE
,
'path_case'
=>
'none'
,
'trim_whitespace'
=>
FALSE
,
'alt'
=>
''
,
'rel'
=>
''
,
'link_class'
=>
''
,
'prefix'
=>
''
,
'suffix'
=>
''
,
'target'
=>
''
,
'nl2br'
=>
FALSE
,
'max_length'
=>
0
,
'word_boundary'
=>
TRUE
,
'ellipsis'
=>
TRUE
,
'more_link'
=>
FALSE
,
'more_link_text'
=>
''
,
'more_link_path'
=>
''
,
'strip_tags'
=>
FALSE
,
'trim'
=>
FALSE
,
'preserve_tags'
=>
''
,
'html'
=>
FALSE
,
],
'element_type'
=>
''
,
'element_class'
=>
''
,
'element_label_type'
=>
''
,
'element_label_class'
=>
''
,
'element_label_colon'
=>
FALSE
,
'element_wrapper_type'
=>
''
,
'element_wrapper_class'
=>
''
,
'element_default_classes'
=>
TRUE
,
'empty'
=>
''
,
'hide_empty'
=>
FALSE
,
'empty_zero'
=>
FALSE
,
'hide_alter_empty'
=>
TRUE
,
'click_sort_column'
=>
'value'
,
'type'
=>
'string'
,
'settings'
=>
[
'link_to_entity'
=>
FALSE
,
],
'group_column'
=>
'value'
,
'group_columns'
=>
[],
'group_rows'
=>
TRUE
,
'delta_limit'
=>
0
,
'delta_offset'
=>
0
,
'delta_reversed'
=>
FALSE
,
'delta_first_last'
=>
FALSE
,
'multi_type'
=>
'separator'
,
'separator'
=>
', '
,
'field_api_classes'
=>
FALSE
,
'entity_type'
=>
'media'
,
'entity_field'
=>
'name'
,
'plugin_id'
=>
'field'
,
];
}
// Check if the edit link field already exists and add if it doesn't.
if
(
!
isset
(
$fields
[
'edit_media'
]))
{
$fields
[
'edit_media'
]
=
[
'id'
=>
'edit_media'
,
'table'
=>
'media'
,
'field'
=>
'edit_media'
,
'relationship'
=>
'none'
,
'group_type'
=>
'group'
,
'admin_label'
=>
''
,
'label'
=>
''
,
'exclude'
=>
FALSE
,
'alter'
=>
[
'alter_text'
=>
TRUE
,
'text'
=>
'Edit {{ name }}'
,
'make_link'
=>
TRUE
,
'path'
=>
''
,
'absolute'
=>
FALSE
,
'external'
=>
FALSE
,
'replace_spaces'
=>
FALSE
,
'path_case'
=>
'none'
,
'trim_whitespace'
=>
FALSE
,
'alt'
=>
'Edit {{ name }}'
,
'rel'
=>
''
,
'link_class'
=>
'media-library-item__edit'
,
'prefix'
=>
''
,
'suffix'
=>
''
,
'target'
=>
''
,
'nl2br'
=>
FALSE
,
'max_length'
=>
0
,
'word_boundary'
=>
TRUE
,
'ellipsis'
=>
TRUE
,
'more_link'
=>
FALSE
,
'more_link_text'
=>
''
,
'more_link_path'
=>
''
,
'strip_tags'
=>
FALSE
,
'trim'
=>
FALSE
,
'preserve_tags'
=>
''
,
'html'
=>
FALSE
,
],
'element_type'
=>
''
,
'element_class'
=>
''
,
'element_label_type'
=>
''
,
'element_label_class'
=>
''
,
'element_label_colon'
=>
FALSE
,
'element_wrapper_type'
=>
'0'
,
'element_wrapper_class'
=>
''
,
'element_default_classes'
=>
FALSE
,
'empty'
=>
''
,
'hide_empty'
=>
FALSE
,
'empty_zero'
=>
FALSE
,
'hide_alter_empty'
=>
TRUE
,
'text'
=>
'Edit'
,
'output_url_as_text'
=>
FALSE
,
'absolute'
=>
FALSE
,
'entity_type'
=>
'media'
,
'plugin_id'
=>
'entity_link_edit'
,
];
}
// Check if the delete link field already exists and add if it doesn't.
if
(
!
isset
(
$fields
[
'delete_media'
]))
{
$fields
[
'delete_media'
]
=
[
'id'
=>
'delete_media'
,
'table'
=>
'media'
,
'field'
=>
'delete_media'
,
'relationship'
=>
'none'
,
'group_type'
=>
'group'
,
'admin_label'
=>
''
,
'label'
=>
''
,
'exclude'
=>
FALSE
,
'alter'
=>
[
'alter_text'
=>
TRUE
,
'text'
=>
'Delete {{ name }}'
,
'make_link'
=>
TRUE
,
'path'
=>
''
,
'absolute'
=>
FALSE
,
'external'
=>
FALSE
,
'replace_spaces'
=>
FALSE
,
'path_case'
=>
'none'
,
'trim_whitespace'
=>
FALSE
,
'alt'
=>
'Delete {{ name }}'
,
'rel'
=>
''
,
'link_class'
=>
'media-library-item__remove'
,
'prefix'
=>
''
,
'suffix'
=>
''
,
'target'
=>
''
,
'nl2br'
=>
FALSE
,
'max_length'
=>
0
,
'word_boundary'
=>
TRUE
,
'ellipsis'
=>
TRUE
,
'more_link'
=>
FALSE
,
'more_link_text'
=>
''
,
'more_link_path'
=>
''
,
'strip_tags'
=>
FALSE
,
'trim'
=>
FALSE
,
'preserve_tags'
=>
''
,
'html'
=>
FALSE
,
],
'element_type'
=>
''
,
'element_class'
=>
''
,
'element_label_type'
=>
''
,
'element_label_class'
=>
''
,
'element_label_colon'
=>
FALSE
,
'element_wrapper_type'
=>
'0'
,
'element_wrapper_class'
=>
''
,
'element_default_classes'
=>
FALSE
,
'empty'
=>
''
,
'hide_empty'
=>
FALSE
,
'empty_zero'
=>
FALSE
,
'hide_alter_empty'
=>
TRUE
,
'text'
=>
'Delete'
,
'output_url_as_text'
=>
FALSE
,
'absolute'
=>
FALSE
,
'entity_type'
=>
'media'
,
'plugin_id'
=>
'entity_link_delete'
,
];
}
// Move the rendered entity field to the last position for accessibility.
$rendered_entity
=
$fields
[
'rendered_entity'
];
unset
(
$fields
[
'rendered_entity'
]);
$fields
[
'rendered_entity'
]
=
$rendered_entity
;
$view
->
set
(
'display.page.display_options.fields'
,
$fields
)
->
save
(
TRUE
);
}
// This update function previously added 'edit' and 'delete' buttons to media
// items in the 'media' view. It has been converted to a post-update hook.
// @see media_library_post_update_add_buttons_to_page_view()
}
This diff is collapsed.
Click to expand it.
core/modules/media_library/media_library.post_update.php
+
222
−
0
View file @
9cf15532
...
...
@@ -307,3 +307,225 @@ function media_library_post_update_add_status_extra_filter() {
]);
}
}
/**
* Add edit and delete button to media library view page display.
*/
function
media_library_post_update_add_buttons_to_page_view
()
{
$view
=
Views
::
getView
(
'media_library'
);
if
(
!
$view
)
{
return
;
}
$display
=
&
$view
->
storage
->
getDisplay
(
'page'
);
if
(
$display
)
{
// Fetch the fields from the page display, if the fields are not yet
// overridden, get the fields from the default display.
if
(
empty
(
$display
[
'display_options'
][
'fields'
]))
{
$defaults
=
$view
->
storage
->
getDisplay
(
'default'
);
$display
[
'display_options'
][
'fields'
]
=
$defaults
[
'display_options'
][
'fields'
];
// Override the fields for the page display.
$display
[
'display_options'
][
'defaults'
][
'fields'
]
=
FALSE
;
}
$fields
=
$display
[
'display_options'
][
'fields'
];
// Check if the name field already exists and add if it doesn't.
if
(
!
isset
(
$fields
[
'name'
]))
{
$fields
[
'name'
]
=
[
'id'
=>
'name'
,
'table'
=>
'media_field_data'
,
'field'
=>
'name'
,
'relationship'
=>
'none'
,
'group_type'
=>
'group'
,
'admin_label'
=>
''
,
'label'
=>
''
,
'exclude'
=>
TRUE
,
'alter'
=>
[
'alter_text'
=>
FALSE
,
'text'
=>
''
,
'make_link'
=>
FALSE
,
'path'
=>
''
,
'absolute'
=>
FALSE
,
'external'
=>
FALSE
,
'replace_spaces'
=>
FALSE
,
'path_case'
=>
'none'
,
'trim_whitespace'
=>
FALSE
,
'alt'
=>
''
,
'rel'
=>
''
,
'link_class'
=>
''
,
'prefix'
=>
''
,
'suffix'
=>
''
,
'target'
=>
''
,
'nl2br'
=>
FALSE
,
'max_length'
=>
0
,
'word_boundary'
=>
TRUE
,
'ellipsis'
=>
TRUE
,
'more_link'
=>
FALSE
,
'more_link_text'
=>
''
,
'more_link_path'
=>
''
,
'strip_tags'
=>
FALSE
,
'trim'
=>
FALSE
,
'preserve_tags'
=>
''
,
'html'
=>
FALSE
,
],
'element_type'
=>
''
,
'element_class'
=>
''
,
'element_label_type'
=>
''
,
'element_label_class'
=>
''
,
'element_label_colon'
=>
FALSE
,
'element_wrapper_type'
=>
''
,
'element_wrapper_class'
=>
''
,
'element_default_classes'
=>
TRUE
,
'empty'
=>
''
,
'hide_empty'
=>
FALSE
,
'empty_zero'
=>
FALSE
,
'hide_alter_empty'
=>
TRUE
,
'click_sort_column'
=>
'value'
,
'type'
=>
'string'
,
'settings'
=>
[
'link_to_entity'
=>
FALSE
,
],
'group_column'
=>
'value'
,
'group_columns'
=>
[],
'group_rows'
=>
TRUE
,
'delta_limit'
=>
0
,
'delta_offset'
=>
0
,
'delta_reversed'
=>
FALSE
,
'delta_first_last'
=>
FALSE
,
'multi_type'
=>
'separator'
,
'separator'
=>
', '
,
'field_api_classes'
=>
FALSE
,
'entity_type'
=>
'media'
,
'entity_field'
=>
'name'
,
'plugin_id'
=>
'field'
,
];
}
// Check if the edit link field already exists and add if it doesn't.
if
(
!
isset
(
$fields
[
'edit_media'
]))
{
$fields
[
'edit_media'
]
=
[
'id'
=>
'edit_media'
,
'table'
=>
'media'
,
'field'
=>
'edit_media'
,
'relationship'
=>
'none'
,
'group_type'
=>
'group'
,
'admin_label'
=>
''
,
'label'
=>
''
,
'exclude'
=>
FALSE
,
'alter'
=>
[
'alter_text'
=>
TRUE
,
'text'
=>
'Edit {{ name }}'
,
'make_link'
=>
TRUE
,
'path'
=>
''
,
'absolute'
=>
FALSE
,
'external'
=>
FALSE
,
'replace_spaces'
=>
FALSE
,
'path_case'
=>
'none'
,
'trim_whitespace'
=>
FALSE
,
'alt'
=>
'Edit {{ name }}'
,
'rel'
=>
''
,
'link_class'
=>
'media-library-item__edit'
,
'prefix'
=>
''
,
'suffix'
=>
''
,
'target'
=>
''
,
'nl2br'
=>
FALSE
,
'max_length'
=>
0
,
'word_boundary'
=>
TRUE
,
'ellipsis'
=>
TRUE
,
'more_link'
=>
FALSE
,
'more_link_text'
=>
''
,
'more_link_path'
=>
''
,
'strip_tags'
=>
FALSE
,
'trim'
=>
FALSE
,
'preserve_tags'
=>
''
,
'html'
=>
FALSE
,
],
'element_type'
=>
''
,
'element_class'
=>
''
,
'element_label_type'
=>
''
,
'element_label_class'
=>
''
,
'element_label_colon'
=>
FALSE
,
'element_wrapper_type'
=>
'0'
,
'element_wrapper_class'
=>
''
,
'element_default_classes'
=>
FALSE
,
'empty'
=>
''
,
'hide_empty'
=>
FALSE
,
'empty_zero'
=>
FALSE
,
'hide_alter_empty'
=>
TRUE
,
'text'
=>
'Edit'
,
'output_url_as_text'
=>
FALSE
,
'absolute'
=>
FALSE
,
'entity_type'
=>
'media'
,
'plugin_id'
=>
'entity_link_edit'
,
];
}
// Check if the delete link field already exists and add if it doesn't.
if
(
!
isset
(
$fields
[
'delete_media'
]))
{
$fields
[
'delete_media'
]
=
[
'id'
=>
'delete_media'
,
'table'
=>
'media'
,
'field'
=>
'delete_media'
,
'relationship'
=>
'none'
,
'group_type'
=>
'group'
,
'admin_label'
=>
''
,
'label'
=>
''
,
'exclude'
=>
FALSE
,
'alter'
=>
[
'alter_text'
=>
TRUE
,
'text'
=>
'Delete {{ name }}'
,
'make_link'
=>
TRUE
,
'path'
=>
''
,
'absolute'
=>
FALSE
,
'external'
=>
FALSE
,
'replace_spaces'
=>
FALSE
,
'path_case'
=>
'none'
,
'trim_whitespace'
=>
FALSE
,
'alt'
=>
'Delete {{ name }}'
,
'rel'
=>
''
,
'link_class'
=>
'media-library-item__remove'
,
'prefix'
=>
''
,
'suffix'
=>
''
,
'target'
=>
''
,
'nl2br'
=>
FALSE
,
'max_length'
=>
0
,
'word_boundary'
=>
TRUE
,
'ellipsis'
=>
TRUE
,
'more_link'
=>
FALSE
,
'more_link_text'
=>
''
,
'more_link_path'
=>
''
,
'strip_tags'
=>
FALSE
,
'trim'
=>
FALSE
,
'preserve_tags'
=>
''
,
'html'
=>
FALSE
,
],
'element_type'
=>
''
,
'element_class'
=>
''
,
'element_label_type'
=>
''
,
'element_label_class'
=>
''
,
'element_label_colon'
=>
FALSE
,
'element_wrapper_type'
=>
'0'
,
'element_wrapper_class'
=>
''
,
'element_default_classes'
=>
FALSE
,
'empty'
=>
''
,
'hide_empty'
=>
FALSE
,
'empty_zero'
=>
FALSE
,
'hide_alter_empty'
=>
TRUE
,
'text'
=>
'Delete'
,
'output_url_as_text'
=>
FALSE
,
'absolute'
=>
FALSE
,
'entity_type'
=>
'media'
,
'plugin_id'
=>
'entity_link_delete'
,
];
}
// Move the rendered entity field to the last position for accessibility.
$rendered_entity
=
$fields
[
'rendered_entity'
];
unset
(
$fields
[
'rendered_entity'
]);
$fields
[
'rendered_entity'
]
=
$rendered_entity
;
$display
[
'display_options'
][
'fields'
]
=
$fields
;
$view
->
storage
->
save
(
TRUE
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment