diff --git a/islandora.links.action.yml b/islandora.links.action.yml index 8a1f6768..ffd1dd71 100644 --- a/islandora.links.action.yml +++ b/islandora.links.action.yml @@ -1,12 +1,24 @@ +islandora.upload_media: + route_name: islandora.upload_media + title: Upload Media + appears_on: + - view.media_of.page_1 + islandora.add_media_to_node: - route_name: islandora.add_media_form + route_name: islandora.add_media_to_node_page title: Add Media appears_on: - view.media_of.page_1 -islandora.add_children_to_node: - route_name: islandora.add_children_form - title: Add Children +islandora.upload_children: + route_name: islandora.upload_children + title: Upload Children + appears_on: + - view.manage_members.page_1 + +islandora.add_member_to_node: + route_name: islandora.add_member_to_node_page + title: Add Child appears_on: - view.manage_members.page_1 @@ -15,3 +27,9 @@ islandora.reorder_children: title: Reorder Children appears_on: - view.manage_members.page_1 + +islandora.add_collection: + route_name: islandora.add_collection + title: Add Collection + appears_on: + - view.collections.page_1 diff --git a/islandora.routing.yml b/islandora.routing.yml index 99aa690d..da264ff3 100644 --- a/islandora.routing.yml +++ b/islandora.routing.yml @@ -16,24 +16,58 @@ system.islandora_settings: requirements: _permission: 'administer site configuration' -islandora.add_children_form: +islandora.add_member_to_node_page: path: '/node/{node}/members/add' + defaults: + _controller: '\Drupal\islandora\Controller\ManageMembersController::addToNodePage' + _title_callback: '\Drupal\islandora\Controller\ManageMembersController::addTitle' + entity_type_id: node + options: + _admin_route: 'true' + requirements: + _entity_create_any_access: 'node' + +islandora.upload_children: + path: '/node/{node}/members/upload' defaults: _form: '\Drupal\islandora\Form\AddChildrenForm' - _title: 'Add children' + _title: 'Upload Children' options: _admin_route: 'TRUE' requirements: - _permssion: 'create node,create media' + _access: 'TRUE' + #_permssion: 'create node,create media' -islandora.add_media_form: +islandora.add_media_to_node_page: path: '/node/{node}/media/add' + defaults: + _controller: '\Drupal\islandora\Controller\ManageMediaController::addToNodePage' + _title_callback: '\Drupal\islandora\Controller\ManageMediaController::addTitle' + entity_type_id: media + options: + _admin_route: 'true' + requirements: + _entity_create_any_access: 'media' + +islandora.upload_media: + path: '/node/{node}/media/upload' + defaults: _form: '\Drupal\islandora\Form\AddMediaForm' _title: 'Add media' options: _admin_route: 'TRUE' requirements: - _permssion: 'create media' + _custom_access: '\Drupal\islandora\Form\AddMediaForm::access' + +islandora.add_collection: + path: '/collection/add' + defaults: + _controller: '\Drupal\islandora\Controller\AddCollectionController::addCollectionPage' + _title: 'Add Collection' + options: + _admin_route: 'true' + requirements: + _custom_access: '\Drupal\islandora\Controller\AddCollectionController::access' islandora.media_source_update: path: '/media/{media}/source' @@ -49,6 +83,7 @@ islandora.media_source_put_to_node: path: '/node/{node}/media/{media_type}/{taxonomy_term}' defaults: _controller: '\Drupal\islandora\Controller\MediaSourceController::putToNode' + methods: [PUT] requirements: _custom_access: '\Drupal\islandora\Controller\MediaSourceController::putToNodeAccess' diff --git a/modules/islandora_core_feature/config/install/views.view.collections.yml b/modules/islandora_core_feature/config/install/views.view.collections.yml new file mode 100644 index 00000000..f682cf2e --- /dev/null +++ b/modules/islandora_core_feature/config/install/views.view.collections.yml @@ -0,0 +1,481 @@ +langcode: en +status: true +dependencies: + config: + - core.entity_view_mode.node.teaser + module: + - media + - node + - taxonomy + - user +id: collections +label: Collections +module: views +description: 'All collections in the repository' +tag: '' +base_table: node_field_data +base_field: nid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: perm + options: + perm: 'access content' + cache: + type: tag + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: mini + options: + items_per_page: 10 + offset: 0 + id: 0 + total_pages: null + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + tags: + previous: ‹‹ + next: ›› + style: + type: table + options: + grouping: { } + row_class: '' + default_row_class: true + override: true + sticky: false + caption: '' + summary: '' + description: '' + columns: + title: title + info: + title: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + default: '-1' + empty_table: false + row: + type: 'entity:node' + options: + view_mode: teaser + fields: + title: + id: title + table: node_field_data + field: title + relationship: none + group_type: group + admin_label: '' + label: Title + exclude: false + 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: false + ellipsis: false + 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: true + 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: true + 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: node + entity_field: title + plugin_id: field + field_member_of: + id: field_member_of + table: node__field_member_of + field: field_member_of + relationship: reverse__node__field_member_of + group_type: count + admin_label: '' + label: Children + exclude: false + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + set_precision: false + precision: 0 + decimal: . + separator: ', ' + format_plural: 0 + format_plural_string: !!binary MQNAY291bnQ= + prefix: '' + suffix: '' + click_sort_column: target_id + type: entity_reference_label + settings: { } + group_column: entity_id + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + field_api_classes: false + plugin_id: field + field_file_size: + id: field_file_size + table: media__field_file_size + field: field_file_size + relationship: reverse__media__field_media_of + group_type: sum + admin_label: '' + label: 'Disk Usage' + exclude: false + alter: + alter_text: true + text: "{% if field_file_size > (1024 ** 5) %}\r\n {% set size = field_file_size / (1024 ** 5) %}\r\n {% set abbreviation = 'PB' %}\r\n{% elseif field_file_size > (1024 ** 4) %}\r\n {% set size = field_file_size / (1024 ** 4) %}\r\n {% set abbreviation = 'TB' %}\r\n{% elseif field_file_size > (1024 ** 3) %}\r\n {% set size = field_file_size / (1024 ** 3) %}\r\n {% set abbreviation = 'GB' %}\r\n{% elseif field_file_size > (1024 ** 2) %}\r\n {% set size = field_file_size / (1024 ** 2) %}\r\n {% set abbreviation = 'MB' %}\r\n{% elseif field_file_size > 1024 %}\r\n {% set size = field_file_size / 1024 %}\r\n {% set abbreviation = 'KB' %}\r\n{% else %}\r\n {% set size = field_file_size %}\r\n {% set abbreviation = 'B' %}\r\n{% endif %}\r\n\r\n{{ size|round(2, 'common') }} {{ abbreviation }}" + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + set_precision: false + precision: 0 + decimal: . + separator: '' + format_plural: 0 + format_plural_string: !!binary MQNAY291bnQ= + prefix: '' + suffix: '' + click_sort_column: value + type: number_integer + settings: { } + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + field_api_classes: false + plugin_id: field + operations: + id: operations + table: node + field: operations + relationship: none + group_type: group + admin_label: '' + label: 'Operations links' + exclude: false + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + destination: true + entity_type: node + plugin_id: entity_operations + filters: + status: + value: '1' + table: node_field_data + field: status + plugin_id: boolean + entity_type: node + entity_field: status + id: status + expose: + operator: '' + group: 1 + field_external_uri_uri: + id: field_external_uri_uri + table: taxonomy_term__field_external_uri + field: field_external_uri_uri + relationship: field_model + group_type: group + admin_label: '' + operator: '=' + value: 'http://purl.org/dc/dcmitype/Collection' + group: 1 + exposed: false + expose: + operator_id: '' + label: '' + description: '' + use_operator: false + operator: '' + identifier: '' + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + placeholder: '' + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + plugin_id: string + sorts: { } + title: Collections + header: { } + footer: { } + empty: { } + relationships: + field_model: + id: field_model + table: node__field_model + field: field_model + relationship: none + group_type: group + admin_label: 'field_model: Taxonomy term' + required: true + plugin_id: standard + reverse__node__field_member_of: + id: reverse__node__field_member_of + table: node_field_data + field: reverse__node__field_member_of + relationship: none + group_type: group + admin_label: field_member_of + required: false + entity_type: node + plugin_id: entity_reverse + reverse__media__field_media_of: + id: reverse__media__field_media_of + table: node_field_data + field: reverse__media__field_media_of + relationship: none + group_type: group + admin_label: field_media_of + required: false + entity_type: node + plugin_id: entity_reverse + arguments: { } + display_extenders: { } + filter_groups: + operator: AND + groups: + 1: AND + group_by: true + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: 1 + display_options: + display_extenders: { } + path: admin/content/collections + menu: + type: tab + title: Collections + description: '' + expanded: false + parent: '' + weight: -100 + context: '0' + menu_name: admin + tab_options: + type: normal + title: Collections + description: '' + weight: 0 + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } diff --git a/modules/islandora_core_feature/islandora_core_feature.features.yml b/modules/islandora_core_feature/islandora_core_feature.features.yml index 5af003a7..7afcb1b1 100755 --- a/modules/islandora_core_feature/islandora_core_feature.features.yml +++ b/modules/islandora_core_feature/islandora_core_feature.features.yml @@ -14,3 +14,4 @@ required: - field.storage.node.field_model - field.storage.node.field_weight - field.storage.taxonomy_term.field_external_uri + - views.view.collections diff --git a/src/Controller/AddCollectionController.php b/src/Controller/AddCollectionController.php new file mode 100644 index 00000000..97f03ad9 --- /dev/null +++ b/src/Controller/AddCollectionController.php @@ -0,0 +1,47 @@ +utils->getTermForUri('http://purl.org/dc/dcmitype/Collection'); + $field = IslandoraUtils::MODEL_FIELD; + + return $this->generateTypeList( + 'node', + 'node_type', + 'node.add', + 'node.type_add', + $field, + ['query' => ["edit[$field][widget]" => $term->id()]] + ); + } + + /** + * Check if the object being displayed "is Islandora". + * + * @param \Drupal\Core\Routing\RouteMatch $route_match + * The current routing match. + * + * @return \Drupal\Core\Access\AccessResultAllowed|\Drupal\Core\Access\AccessResultForbidden + * Whether we can or can't show the "thing". + */ + public function access(RouteMatch $route_match) { + if ($this->utils->canCreateIslandoraEntity('node', 'node_type')) { + return AccessResult::allowed(); + } + return AccessResult::forbidden(); + } + +} diff --git a/src/Controller/ManageMediaController.php b/src/Controller/ManageMediaController.php index 776a6808..56e0b5c5 100644 --- a/src/Controller/ManageMediaController.php +++ b/src/Controller/ManageMediaController.php @@ -2,6 +2,7 @@ namespace Drupal\islandora\Controller; +use Drupal\islandora\IslandoraUtils; use Drupal\Core\Access\AccessResult; use Drupal\Core\Routing\RouteMatch; use Drupal\node\Entity\Node; @@ -22,13 +23,15 @@ class ManageMediaController extends ManageMembersController { * Array of media types to add. */ public function addToNodePage(NodeInterface $node) { + $field = IslandoraUtils::MEDIA_OF_FIELD; + return $this->generateTypeList( 'media', 'media_type', 'entity.media.add_form', 'entity.media_type.add_form', - $node, - 'field_media_of' + $field, + ['query' => ["edit[$field][widget][0][target_id]" => $node->id()]] ); } @@ -47,7 +50,7 @@ class ManageMediaController extends ManageMembersController { if (!$node instanceof NodeInterface) { $node = Node::load($node); } - if ($node->hasField('field_model') && $node->hasField('field_member_of')) { + if ($this->utils->isIslandoraType($node->getEntityTypeId(), $node->bundle())) { return AccessResult::allowed(); } } diff --git a/src/Controller/ManageMembersController.php b/src/Controller/ManageMembersController.php index 9197811b..37ebde27 100644 --- a/src/Controller/ManageMembersController.php +++ b/src/Controller/ManageMembersController.php @@ -7,6 +7,7 @@ use Drupal\Core\Render\RendererInterface; use Drupal\Core\Entity\Controller\EntityController; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Link; +use Drupal\islandora\IslandoraUtils; use Drupal\node\NodeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -36,6 +37,13 @@ class ManageMembersController extends EntityController { */ protected $renderer; + /** + * Islandora Utils. + * + * @var \Drupal\islandora\IslandoraUtils + */ + protected $utils; + /** * Constructor. * @@ -45,15 +53,19 @@ class ManageMembersController extends EntityController { * The entity field manager. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. + * @param \Drupal\islandora\IslandoraUtils $utils + * Islandora utils. */ public function __construct( EntityTypeManagerInterface $entity_type_manager, - EntityFieldManagerInterface $entity_field_manager, - RendererInterface $renderer + EntityFieldManager $entity_field_manager, + RendererInterface $renderer, + IslandoraUtils $utils ) { $this->entityTypeManager = $entity_type_manager; $this->entityFieldManager = $entity_field_manager; $this->renderer = $renderer; + $this->utils = $utils; } /** @@ -63,7 +75,8 @@ class ManageMembersController extends EntityController { return new static( $container->get('entity_type.manager'), $container->get('entity_field.manager'), - $container->get('renderer') + $container->get('renderer'), + $container->get('islandora.utils') ); } @@ -74,20 +87,21 @@ class ManageMembersController extends EntityController { * Node you want to add a member to. */ public function addToNodePage(NodeInterface $node) { + $field = IslandoraUtils::MEMBER_OF_FIELD; return $this->generateTypeList( 'node', 'node_type', 'node.add', 'node.type_add', - $node, - 'field_member_of' + $field, + ['query' => ["edit[$field][widget][0][target_id]" => $node->id()]] ); } /** * Renders a list of content types to add as members. */ - protected function generateTypeList($entity_type, $bundle_type, $entity_add_form, $bundle_add_form, NodeInterface $node, $field) { + protected function generateTypeList($entity_type, $bundle_type, $entity_add_form, $bundle_add_form, $field, array $url_options) { $type_definition = $this->entityTypeManager->getDefinition($bundle_type); $build = [ @@ -115,7 +129,7 @@ class ManageMembersController extends EntityController { $bundle->label(), $entity_add_form, [$bundle_type => $bundle->id()], - ['query' => ["edit[$field][widget][0][target_id]" => $node->id()]] + $url_options ), ]; } diff --git a/src/Form/AddChildrenForm.php b/src/Form/AddChildrenForm.php index 14b787b3..82332ca8 100644 --- a/src/Form/AddChildrenForm.php +++ b/src/Form/AddChildrenForm.php @@ -4,6 +4,7 @@ namespace Drupal\islandora\Form; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\Core\Routing\RouteMatch; use Drupal\islandora\IslandoraUtils; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -176,4 +177,24 @@ class AddChildrenForm extends AddMediaForm { ); } + /** + * Check if the user can create any "Islandora" nodes and media. + * + * @param \Drupal\Core\Routing\RouteMatch $route_match + * The current routing match. + * + * @return \Drupal\Core\Access\AccessResultAllowed|\Drupal\Core\Access\AccessResultForbidden + * Whether we can or can't show the "thing". + */ + public function access(RouteMatch $route_match) { + $can_create_media = $this->utils->canCreateIslandoraEntity('media', 'media_type'); + $can_create_node = $this->utils->canCreateIslandoraEntity('node', 'node_type'); + + if ($can_create_media && $can_create_node) { + return AccessResult::allowed(); + } + + return AccessResult::forbidden(); + } + } diff --git a/src/Form/AddMediaForm.php b/src/Form/AddMediaForm.php index bb02b414..9b70461e 100644 --- a/src/Form/AddMediaForm.php +++ b/src/Form/AddMediaForm.php @@ -2,11 +2,13 @@ namespace Drupal\islandora\Form; +use Drupal\Core\Access\AccessResult; use Drupal\Core\Config\ImmutableConfig; use Drupal\Core\Database\Connection; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\islandora\IslandoraUtils; use Drupal\islandora\MediaSource\MediaSourceService; @@ -14,6 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\HttpException; use Drupal\Core\Utility\Token; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Routing\RouteMatch; /** * Form that lets users upload one or more files as children to a resource node. @@ -27,6 +30,13 @@ class AddMediaForm extends FormBase { */ protected $entityTypeManager; + /** + * Entity field manager. + * + * @var \Drupal\Core\Entity\EntityFieldManagerInterface + */ + protected $entityFieldManager; + /** * Media source service. * @@ -88,6 +98,7 @@ class AddMediaForm extends FormBase { */ public function __construct( EntityTypeManagerInterface $entity_type_manager, + EntityFieldManagerInterface $entity_field_manager, IslandoraUtils $utils, MediaSourceService $media_source, ImmutableConfig $config, @@ -97,6 +108,7 @@ class AddMediaForm extends FormBase { Connection $database ) { $this->entityTypeManager = $entity_type_manager; + $this->entityFieldManager = $entity_field_manager; $this->utils = $utils; $this->mediaSource = $media_source; $this->config = $config; @@ -112,6 +124,7 @@ class AddMediaForm extends FormBase { public static function create(ContainerInterface $container) { return new static( $container->get('entity_type.manager'), + $container->get('entity_field.manager'), $container->get('islandora.utils'), $container->get('islandora.media_source_service'), $container->get('config.factory')->get('islandora.settings'), @@ -243,4 +256,46 @@ class AddMediaForm extends FormBase { } } + /** + * Check if the user can create any "Islandora" media. + * + * @param \Drupal\Core\Routing\RouteMatch $route_match + * The current routing match. + * + * @return \Drupal\Core\Access\AccessResultAllowed|\Drupal\Core\Access\AccessResultForbidden + * Whether we can or can't show the "thing". + */ + public function access(RouteMatch $route_match) { + if ($this->utils->canCreateIslandoraEntity('media', 'media_type')) { + return AccessResult::allowed(); + } + + return AccessResult::forbidden(); + } + + /** + * Utility function to check if user can create 'Islandora' entity types. + */ + protected function canCreateIslandoraEntity($entity_type, $bundle_type) { + $bundles = $this->entityTypeManager->getStorage($bundle_type)->loadMultiple(); + $access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type); + + $allowed = []; + foreach (array_keys($bundles) as $bundle) { + // Skip bundles that aren't 'Islandora' types. + if (!$this->utils->isIslandoraType($entity_type, $bundle)) { + continue; + } + + $access = $access_control_handler->createAccess($bundle, NULL, [], TRUE); + if (!$access->isAllowed()) { + continue; + } + + return TRUE; + } + + return FALSE; + } + } diff --git a/src/IslandoraUtils.php b/src/IslandoraUtils.php index 94fac4bc..463227e3 100644 --- a/src/IslandoraUtils.php +++ b/src/IslandoraUtils.php @@ -638,4 +638,37 @@ class IslandoraUtils { } } + /** + * Util function for access handlers . + * + * @param string $entity_type + * Entity type such as 'node', 'media', 'taxonomy_term', etc.. + * @param string $bundle_type + * Bundle type such as 'node_type', 'media_type', 'vocabulary', etc... + * + * @return bool + * If user can create _at least one_ of the 'Islandora' types requested. + */ + public function canCreateIslandoraEntity($entity_type, $bundle_type) { + $bundles = $this->entityTypeManager->getStorage($bundle_type)->loadMultiple(); + $access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type); + + $allowed = []; + foreach (array_keys($bundles) as $bundle) { + // Skip bundles that aren't 'Islandora' types. + if (!$this->isIslandoraType($entity_type, $bundle)) { + continue; + } + + $access = $access_control_handler->createAccess($bundle, NULL, [], TRUE); + if (!$access->isAllowed()) { + continue; + } + + return TRUE; + } + + return FALSE; + } + } diff --git a/tests/src/Functional/AddChildTest.php b/tests/src/Functional/AddChildTest.php new file mode 100644 index 00000000..67bc6233 --- /dev/null +++ b/tests/src/Functional/AddChildTest.php @@ -0,0 +1,60 @@ +parent = + $this->collectionTerm = $this->container->get('entity_type.manager')->getStorage('taxonomy_term')->create([ + 'name' => 'Collection', + 'vid' => $this->testVocabulary->id(), + 'field_external_uri' => [['uri' => "http://purl.org/dc/dcmitype/Collection"]], + ]); + $this->collectionTerm->save(); + } + + /** + * @covers \Drupal\islandora\Controller\AddCollectionController::addToNodePage + * @covers \Drupal\islandora\Controller\AddCollectionController::access + * @covers \Drupal\islandora\IslandoraUtils::isIslandoraType + */ + public function testAddChild() { + $account = $this->drupalCreateUser([ + 'bypass node access', + ]); + $this->drupalLogin($account); + + $parent = $this->container->get('entity_type.manager')->getStorage('node')->create([ + 'type' => 'test_type', + 'title' => 'Parent', + ]); + $parent->save(); + + // Visit the add member page. + $this->drupalGet("/node/{$parent->id()}/members/add"); + + // Assert that test_type is on the list. + $this->assertSession()->pageTextContains($this->testType->label()); + $this->clickLink($this->testType->label()); + $url = $this->getUrl(); + + // Assert that the link creates the correct prepopulate query param. + $substring = 'node/add/test_type?edit%5Bfield_member_of%5D%5Bwidget%5D%5B0%5D%5Btarget_id%5D=1'; + $this->assertTrue( + strpos($url, $substring) !== FALSE, + "Malformed URL, could not find $substring in $url." + ); + } + +} diff --git a/tests/src/Functional/AddCollectionTest.php b/tests/src/Functional/AddCollectionTest.php new file mode 100644 index 00000000..f1a87ab7 --- /dev/null +++ b/tests/src/Functional/AddCollectionTest.php @@ -0,0 +1,62 @@ +collectionTerm = $this->container->get('entity_type.manager')->getStorage('taxonomy_term')->create([ + 'name' => 'Collection', + 'vid' => $this->testVocabulary->id(), + 'field_external_uri' => [['uri' => "http://purl.org/dc/dcmitype/Collection"]], + ]); + $this->collectionTerm->save(); + } + + /** + * @covers \Drupal\islandora\Controller\AddCollectionController::addCollectionPage + * @covers \Drupal\islandora\Controller\AddCollectionController::access + * @covers \Drupal\islandora\IslandoraUtils::isIslandoraType + */ + public function testAddCollection() { + $account = $this->drupalCreateUser([ + 'bypass node access', + ]); + $this->drupalLogin($account); + + // Visit the add collection page. + $this->drupalGet('/collection/add'); + + // Assert the test type is in the list of available types. + $this->assertSession()->pageTextContains($this->testType->label()); + + // Click the test type and make sure you get sent to the right form. + $this->clickLink($this->testType->label()); + $url = $this->getUrl(); + + // Assert that the link creates the correct prepopulate query param. + $substring = 'node/add/test_type?edit%5Bfield_model%5D%5Bwidget%5D=1'; + $this->assertTrue( + strpos($url, 'node/add/test_type?edit%5Bfield_model%5D%5Bwidget%5D=1') !== FALSE, + "Malformed URL, could not find $substring in $url." + ); + } + +} diff --git a/tests/src/Functional/AddMediaTest.php b/tests/src/Functional/AddMediaTest.php new file mode 100644 index 00000000..f91cef82 --- /dev/null +++ b/tests/src/Functional/AddMediaTest.php @@ -0,0 +1,46 @@ +drupalCreateUser([ + 'bypass node access', + 'create media', + ]); + $this->drupalLogin($account); + + $parent = $this->container->get('entity_type.manager')->getStorage('node')->create([ + 'type' => 'test_type', + 'title' => 'Parent', + ]); + $parent->save(); + + // Visit the add media page. + $this->drupalGet("/node/{$parent->id()}/media/add"); + + // Assert that test_meida_type is on the list. + $this->assertSession()->pageTextContains($this->testMediaType->label()); + $this->clickLink($this->testMediaType->label()); + $url = $this->getUrl(); + + // Assert that the link creates the correct prepopulate query param. + $substring = 'media/add/test_media_type?edit%5Bfield_media_of%5D%5Bwidget%5D%5B0%5D%5Btarget_id%5D=1'; + $this->assertTrue( + strpos($url, $substring) !== FALSE, + "Malformed URL, could not find $substring in $url." + ); + } + +} diff --git a/tests/src/Functional/GenerateDerivativeTestBase.php b/tests/src/Functional/GenerateDerivativeTestBase.php index c74ff255..0f67d591 100644 --- a/tests/src/Functional/GenerateDerivativeTestBase.php +++ b/tests/src/Functional/GenerateDerivativeTestBase.php @@ -48,7 +48,7 @@ abstract class GenerateDerivativeTestBase extends IslandoraFunctionalTestBase { $this->node = $this->container->get('entity_type.manager')->getStorage('node')->create([ 'type' => $this->testType->id(), 'title' => 'Test Node', - 'field_tags' => [$this->imageTerm->id()], + 'field_model' => [$this->imageTerm->id()], ]); $this->node->save(); } diff --git a/tests/src/Functional/IslandoraFunctionalTestBase.php b/tests/src/Functional/IslandoraFunctionalTestBase.php index a948daa4..c154c5c2 100644 --- a/tests/src/Functional/IslandoraFunctionalTestBase.php +++ b/tests/src/Functional/IslandoraFunctionalTestBase.php @@ -204,13 +204,13 @@ EOD; ]); $this->testType->save(); $this->createEntityReferenceField('node', 'test_type', 'field_member_of', 'Member Of', 'node', 'default', [], 2); - $this->createEntityReferenceField('node', 'test_type', 'field_tags', 'Tags', 'taxonomy_term', 'default', [], 2); + $this->createEntityReferenceField('node', 'test_type', 'field_model', 'Model', 'taxonomy_term', 'default', [], 2); // Create a media type. $this->testMediaType = $this->createMediaType('file', ['id' => 'test_media_type']); $this->testMediaType->save(); $this->createEntityReferenceField('media', $this->testMediaType->id(), 'field_media_of', 'Media Of', 'node', 'default', [], 2); - $this->createEntityReferenceField('media', $this->testMediaType->id(), 'field_tags', 'Tags', 'taxonomy_term', 'default', [], 2); + $this->createEntityReferenceField('media', $this->testMediaType->id(), 'field_media_use', 'Tags', 'taxonomy_term', 'default', [], 2); // Copy over the rest of the config from yml files. $source = new FileStorage(__DIR__ . '/../../fixtures/config'); diff --git a/tests/src/Functional/LinkHeaderTest.php b/tests/src/Functional/LinkHeaderTest.php index 1cd1e0a8..7cb741d5 100644 --- a/tests/src/Functional/LinkHeaderTest.php +++ b/tests/src/Functional/LinkHeaderTest.php @@ -61,13 +61,13 @@ class LinkHeaderTest extends IslandoraFunctionalTestBase { 'type' => $this->testType->id(), 'title' => 'Referencer', 'field_member_of' => [$this->referenced->id()], - 'field_tags' => [$this->imageTerm->id()], + 'field_model' => [$this->imageTerm->id()], ]); $this->referencer->save(); list($this->file, $this->media) = $this->makeMediaAndFile($account); $this->media->set('field_media_of', $this->referencer); - $this->media->set('field_tags', $this->preservationMasterTerm); + $this->media->set('field_media_use', $this->preservationMasterTerm); $this->media->save(); } diff --git a/tests/src/Functional/NodeHasTermTest.php b/tests/src/Functional/NodeHasTermTest.php index 1d4dd44c..6cc103ef 100644 --- a/tests/src/Functional/NodeHasTermTest.php +++ b/tests/src/Functional/NodeHasTermTest.php @@ -72,17 +72,6 @@ class NodeHasTermTest extends IslandoraFunctionalTestBase { $condition->setContextValue('node', $node); $this->assertFalse($condition->execute(), "Condition should fail if the node has terms, but not the one we want."); - // Check for two tags this time. - // Node still only has one. - $condition = $condition_manager->createInstance( - 'node_has_term', - [ - 'uri' => 'http://purl.org/coar/resource_type/c_c513,http://pcdm.org/use#PreservationMasterFile', - ] - ); - $condition->setContextValue('node', $node); - $this->assertFalse($condition->execute(), "Condition should fail if node does not have both terms"); - // Check for two tags this time. // Node still only has one. $condition = $condition_manager->createInstance(