1414use Drupal \Core \Plugin \ContainerFactoryPluginInterface ;
1515use Drupal \Core \Url ;
1616use Drupal \media \Entity \Media ;
17- use Drupal \media_library \Form \MediaLibraryUploadForm ;
1817use Symfony \Component \DependencyInjection \ContainerInterface ;
1918use Symfony \Component \Validator \ConstraintViolationInterface ;
2019
@@ -42,13 +41,6 @@ class MediaLibraryWidget extends WidgetBase implements ContainerFactoryPluginInt
4241 */
4342 protected $ entityTypeManager ;
4443
45- /**
46- * Indicates whether or not the add button should be shown.
47- *
48- * @var bool
49- */
50- protected $ addAccess = FALSE ;
51-
5244 /**
5345 * Constructs a MediaLibraryWidget widget.
5446 *
@@ -64,30 +56,23 @@ class MediaLibraryWidget extends WidgetBase implements ContainerFactoryPluginInt
6456 * Any third party settings.
6557 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
6658 * Entity type manager service.
67- * @param bool $add_access
68- * Indicates whether or not the add button should be shown.
6959 */
70- public function __construct ($ plugin_id , $ plugin_definition , FieldDefinitionInterface $ field_definition , array $ settings , array $ third_party_settings , EntityTypeManagerInterface $ entity_type_manager, $ add_access ) {
60+ public function __construct ($ plugin_id , $ plugin_definition , FieldDefinitionInterface $ field_definition , array $ settings , array $ third_party_settings , EntityTypeManagerInterface $ entity_type_manager ) {
7161 parent ::__construct ($ plugin_id , $ plugin_definition , $ field_definition , $ settings , $ third_party_settings );
7262 $ this ->entityTypeManager = $ entity_type_manager ;
73- $ this ->addAccess = $ add_access ;
7463 }
7564
7665 /**
7766 * {@inheritdoc}
7867 */
7968 public static function create (ContainerInterface $ container , array $ configuration , $ plugin_id , $ plugin_definition ) {
80- $ settings = $ configuration ['field_definition ' ]->getSettings ()['handler_settings ' ];
81- $ target_bundles = isset ($ settings ['target_bundles ' ]) ? $ settings ['target_bundles ' ] : NULL ;
8269 return new static (
8370 $ plugin_id ,
8471 $ plugin_definition ,
8572 $ configuration ['field_definition ' ],
8673 $ configuration ['settings ' ],
8774 $ configuration ['third_party_settings ' ],
88- $ container ->get ('entity_type.manager ' ),
89- // @todo Use URL access in https://www.drupal.org/node/2956747
90- MediaLibraryUploadForm::create ($ container )->access ($ target_bundles )->isAllowed ()
75+ $ container ->get ('entity_type.manager ' )
9176 );
9277 }
9378
@@ -247,7 +232,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
247232 // Add a button that will load the Media library in a modal using AJAX.
248233 $ element ['media_library_open_button ' ] = [
249234 '#type ' => 'link ' ,
250- '#title ' => $ this ->t ('Browse media ' ),
235+ '#title ' => $ this ->t ('Add media ' ),
251236 '#name ' => $ field_name . '-media-library-open-button ' . $ id_suffix ,
252237 // @todo Make the view configurable in https://www.drupal.org/project/drupal/issues/2971209
253238 '#url ' => Url::fromRoute ('view.media_library.widget ' , [], [
@@ -263,23 +248,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
263248 '#access ' => $ cardinality_unlimited || $ remaining > 0 ,
264249 ];
265250
266- $ element ['media_library_add_button ' ] = [
267- '#type ' => 'link ' ,
268- '#title ' => $ this ->t ('Add media ' ),
269- '#name ' => $ field_name . '-media-library-add-button ' . $ id_suffix ,
270- '#url ' => Url::fromRoute ('media_library.upload ' , [], [
271- 'query ' => $ query ,
272- ]),
273- '#attributes ' => [
274- 'class ' => ['button ' , 'use-ajax ' , 'media-library-add-button ' ],
275- 'data-dialog-type ' => 'modal ' ,
276- 'data-dialog-options ' => $ dialog_options ,
277- ],
278- // Prevent errors in other widgets from preventing addition.
279- '#limit_validation_errors ' => $ limit_validation_errors ,
280- '#access ' => $ this ->addAccess && ($ cardinality_unlimited || $ remaining > 0 ),
281- ];
282-
283251 // This hidden field and button are used to add new items to the widget.
284252 $ element ['media_library_selection ' ] = [
285253 '#type ' => 'hidden ' ,
0 commit comments