Skip to content
Snippets Groups Projects
Unverified Commit 7064c439 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3173770 by chr.fritsch, phenaproxima, akalam, dejan0: Allow field types...

Issue #3173770 by chr.fritsch, phenaproxima, akalam, dejan0: Allow field types extending entity_reference to use field widgets extending media_library
parent afdff8f9
No related branches found
No related tags found
31 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!2074Issue #2707689: NodeForm::actions() checks for delete access on new entities,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!1459Issue #3087632: menu_name max length is too long,!1283Issue #2922435: "Add new comment" and "@count comments" links are not following accessibility good practices,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1254Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS,!1213Issue #3236497: Allow other modules to opt out of security release message from update_page_top,!1185Issue 318778: Rerolled patch.,!1162Issue #3100350: Unable to save '/' root path alias,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!1018Issue #2793343: Dialog drupalAutoButtons option should be respected on initial load,!1014Issue #3226806: Move filter implementations from filter.module to plugin classes,!957Added throwing of InvalidPluginDefinitionException from getDefinition().,!939Issue #2971209: Allow the MediaLibraryUiBuilder service to use an alternative view display,!878Issue #3221534: throw an exception when IDs passed to loadMultiple() are badly formed,!877Issue #2708101: Default value for link text is not saved,!873Issue #2875228: Site install not using batch API service,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!866Issue #2845319: The highlighting of the 'Home' menu-link does not respect query strings and fragment identifiers,!844Resolve #3036010 "Updaters",!8293023322 - Contextual Links Style Update,!712Issue #2909128: Autocomplete intermittent on Chrome Android,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -9,6 +9,7 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Field\EntityReferenceFieldItemList;
/**
* The media library opener for field widgets.
......@@ -95,7 +96,9 @@ public function checkAccess(MediaLibraryState $state, AccountInterface $account)
$items = $entity->get($field_name);
$field_definition = $items->getFieldDefinition();
if ($field_definition->getType() !== 'entity_reference') {
// Check that the field is an entity reference, or subclass of it, since we
// need to check the target_type setting.
if (!$items instanceof EntityReferenceFieldItemList) {
throw new \LogicException('Expected the media library to be opened by an entity reference field.');
}
if ($field_definition->getFieldStorageDefinition()->getSetting('target_type') !== 'media') {
......
field.storage_settings.entity_reference_subclass:
type: base_entity_reference_field_settings
label: 'Entity reference subclass field storage settings'
field.field_settings.entity_reference_subclass:
type: field.field_settings.entity_reference
label: 'Entity reference subclass field settings'
......@@ -39,3 +39,10 @@ function media_library_test_entity_type_alter(array &$entity_types) {
$entity_types['node']->setFormClass('edit', TestNodeFormOverride::class);
}
}
/**
* Implements hook_field_widget_info_alter().
*/
function media_library_test_field_widget_info_alter(array &$info) {
$info['media_library_widget']['field_types'][] = 'entity_reference_subclass';
}
<?php
namespace Drupal\media_library_test\Plugin\Field\FieldType;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
/**
* Plugin implementation of the 'entity_reference_subclass' field type.
*
* @FieldType(
* id = "entity_reference_subclass",
* label = @Translation("Entity reference subclass"),
* description = @Translation("An entity field containing an entity reference."),
* category = @Translation("Reference"),
* default_widget = "entity_reference_autocomplete",
* default_formatter = "entity_reference_label",
* list_class = "\Drupal\Core\Field\EntityReferenceFieldItemList"
* )
*/
class EntityReferenceItemSubclass extends EntityReferenceItem {
}
......@@ -256,12 +256,30 @@ public function testFieldWidgetEntityEditAccess() {
$this->assertAccess($access_result, TRUE, NULL, Views::getView('media_library')->storage->getCacheTags(), ['url.query_args', 'user.permissions']);
}
/**
* Data provider for ::testFieldWidgetEntityFieldAccess().
*
* @return array[]
* Sets of arguments to pass to the test method.
*/
public function providerFieldWidgetEntityFieldAccess(): array {
return [
['entity_reference'],
['entity_reference_subclass'],
];
}
/**
* Tests that the field widget opener respects entity field-level access.
*
* @param string $field_type
* The field type.
*
* @dataProvider providerFieldWidgetEntityFieldAccess
*/
public function testFieldWidgetEntityFieldAccess() {
public function testFieldWidgetEntityFieldAccess(string $field_type) {
$field_storage = FieldStorageConfig::create([
'type' => 'entity_reference',
'type' => $field_type,
'entity_type' => 'entity_test',
// The media_library_test module will deny access to this field.
// @see media_library_test_entity_field_access()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment