From 07f69a80da1a5141caad6b8bd0ffe1c6cbc4cd80 Mon Sep 17 00:00:00 2001 From: dannylamb Date: Thu, 1 Jun 2017 08:36:46 -0300 Subject: [PATCH] Issue 643 (#63) * First pass with the flamethrower * Updates after testing. Rules * Updates from testing on fresh install * Forgot these --- ...ntity_view_mode.fedora_resource.teaser.yml | 13 - .../field.field.media.tn.field_height.yml | 3 + ... field.storage.node.field_description.yml} | 4 +- ... => field.storage.node.field_memberof.yml} | 6 +- ...j.yml => field.storage.node.field_obj.yml} | 4 +- ...tn.yml => field.storage.node.field_tn.yml} | 4 +- .../rest.resource.entity.fedora_resource.yml | 26 - config/install/rest.resource.entity.media.yml | 23 +- ...action.broadcast_content_create_event.yml} | 27 +- ...action.broadcast_content_delete_event.yml} | 27 +- ...action.broadcast_content_update_event.yml} | 27 +- ....reaction.broadcast_media_create_event.yml | 16 +- ....reaction.broadcast_media_delete_event.yml | 16 +- ....reaction.broadcast_media_update_event.yml | 16 +- .../views.view.fedora_entities_reference.yml | 169 ---- config/install/views.view.membership_view.yml | 216 ----- config/schema/fedora_resource_type.schema.yml | 24 - fedora_resource.page.inc | 71 -- islandora.install | 18 + islandora.links.action.yml | 10 - islandora.links.menu.yml | 8 - islandora.links.task.yml | 21 - islandora.module | 40 +- islandora.permissions.yml | 26 - islandora.routing.yml | 10 +- .../FedoraResourceAddController.php | 119 --- ...roller.php => JsonLdContextController.php} | 16 +- src/Entity/FedoraResource.php | 465 ---------- src/Entity/FedoraResourceType.php | 57 -- src/Entity/FedoraResourceViewsData.php | 31 - src/FedoraResourceAccessControlHandler.php | 48 - src/FedoraResourceHtmlRouteProvider.php | 184 ---- src/FedoraResourceInterface.php | 119 --- src/FedoraResourceListBuilder.php | 48 - src/FedoraResourceTypeHtmlRouteProvider.php | 97 -- src/FedoraResourceTypeInterface.php | 13 - src/FedoraResourceTypeListBuilder.php | 32 - src/FedoraResourceViewBuilder.php | 18 - src/Form/FedoraResourceDeleteForm.php | 15 - src/Form/FedoraResourceEntityInlineForm.php | 287 ------ src/Form/FedoraResourceForm.php | 48 - src/Form/FedoraResourceSettingsForm.php | 55 -- src/Form/FedoraResourceTypeDeleteForm.php | 53 -- src/Form/FedoraResourceTypeForm.php | 67 -- src/Plugin/Search/FedoraEntitySearch.php | 839 ------------------ src/Plugin/views/wizard/FedoraResource.php | 130 --- .../Web/JsonldContextGeneratorWebTest.php | 36 +- ...fedora-resource-content-add-list.html.twig | 23 - templates/fedora_resource.html.twig | 22 - .../DeleteFedoraResourceWithParentsTest.php | 92 -- tests/src/Kernel/EventGeneratorTestBase.php | 17 +- .../Kernel/FedoraContentTypeCreationTrait.php | 43 - tests/src/Kernel/FedoraResourceParentTest.php | 134 --- tests/src/Kernel/IslandoraKernelTestBase.php | 3 +- tests/src/Kernel/VersionCounterTest.php | 23 +- 55 files changed, 158 insertions(+), 3801 deletions(-) delete mode 100644 config/install/core.entity_view_mode.fedora_resource.teaser.yml rename config/install/{field.storage.fedora_resource.field_description.yml => field.storage.node.field_description.yml} (82%) rename config/install/{field.storage.fedora_resource.field_memberof.yml => field.storage.node.field_memberof.yml} (75%) rename config/install/{field.storage.fedora_resource.field_obj.yml => field.storage.node.field_obj.yml} (86%) rename config/install/{field.storage.fedora_resource.field_tn.yml => field.storage.node.field_tn.yml} (86%) delete mode 100644 config/install/rest.resource.entity.fedora_resource.yml rename config/install/{rules.reaction.broadcast_create_event.yml => rules.reaction.broadcast_content_create_event.yml} (59%) rename config/install/{rules.reaction.broadcast_delete_event.yml => rules.reaction.broadcast_content_delete_event.yml} (59%) rename config/install/{rules.reaction.broadcast_update_event.yml => rules.reaction.broadcast_content_update_event.yml} (59%) delete mode 100644 config/install/views.view.fedora_entities_reference.yml delete mode 100644 config/install/views.view.membership_view.yml delete mode 100644 config/schema/fedora_resource_type.schema.yml delete mode 100644 fedora_resource.page.inc delete mode 100644 islandora.links.action.yml delete mode 100644 islandora.links.task.yml delete mode 100644 islandora.permissions.yml delete mode 100644 src/Controller/FedoraResourceAddController.php rename src/Controller/{FedoraResourceJsonLdContextController.php => JsonLdContextController.php} (83%) delete mode 100644 src/Entity/FedoraResource.php delete mode 100644 src/Entity/FedoraResourceType.php delete mode 100644 src/Entity/FedoraResourceViewsData.php delete mode 100644 src/FedoraResourceAccessControlHandler.php delete mode 100644 src/FedoraResourceHtmlRouteProvider.php delete mode 100644 src/FedoraResourceInterface.php delete mode 100644 src/FedoraResourceListBuilder.php delete mode 100644 src/FedoraResourceTypeHtmlRouteProvider.php delete mode 100644 src/FedoraResourceTypeInterface.php delete mode 100644 src/FedoraResourceTypeListBuilder.php delete mode 100644 src/FedoraResourceViewBuilder.php delete mode 100644 src/Form/FedoraResourceDeleteForm.php delete mode 100644 src/Form/FedoraResourceEntityInlineForm.php delete mode 100644 src/Form/FedoraResourceForm.php delete mode 100644 src/Form/FedoraResourceSettingsForm.php delete mode 100644 src/Form/FedoraResourceTypeDeleteForm.php delete mode 100644 src/Form/FedoraResourceTypeForm.php delete mode 100644 src/Plugin/Search/FedoraEntitySearch.php delete mode 100644 src/Plugin/views/wizard/FedoraResource.php delete mode 100644 templates/fedora-resource-content-add-list.html.twig delete mode 100644 templates/fedora_resource.html.twig delete mode 100644 tests/src/Kernel/DeleteFedoraResourceWithParentsTest.php delete mode 100644 tests/src/Kernel/FedoraContentTypeCreationTrait.php delete mode 100644 tests/src/Kernel/FedoraResourceParentTest.php diff --git a/config/install/core.entity_view_mode.fedora_resource.teaser.yml b/config/install/core.entity_view_mode.fedora_resource.teaser.yml deleted file mode 100644 index be1fa1a3..00000000 --- a/config/install/core.entity_view_mode.fedora_resource.teaser.yml +++ /dev/null @@ -1,13 +0,0 @@ -uuid: 0efc20d3-0bd6-4606-842f-b87548de1924 -langcode: en -status: true -dependencies: - enforced: - module: - - islandora -_core: - default_config_hash: PnOwgzHIcT0m2y9dN2B5D7og29JXDCm4dCqb1pKUWek -id: fedora_resource.teaser -label: Teaser -targetEntityType: fedora_resource -cache: true diff --git a/config/install/field.field.media.tn.field_height.yml b/config/install/field.field.media.tn.field_height.yml index bd9f23e2..af401b7c 100644 --- a/config/install/field.field.media.tn.field_height.yml +++ b/config/install/field.field.media.tn.field_height.yml @@ -5,6 +5,9 @@ dependencies: config: - field.storage.media.field_height - media_entity.bundle.tn + enforced: + module: + - islandora id: media.tn.field_height field_name: field_height entity_type: media diff --git a/config/install/field.storage.fedora_resource.field_description.yml b/config/install/field.storage.node.field_description.yml similarity index 82% rename from config/install/field.storage.fedora_resource.field_description.yml rename to config/install/field.storage.node.field_description.yml index 8c7b2a6a..22a1f37d 100644 --- a/config/install/field.storage.fedora_resource.field_description.yml +++ b/config/install/field.storage.node.field_description.yml @@ -6,9 +6,9 @@ dependencies: enforced: module: - islandora -id: fedora_resource.field_description +id: node.field_description field_name: field_description -entity_type: fedora_resource +entity_type: node type: string_long settings: case_sensitive: false diff --git a/config/install/field.storage.fedora_resource.field_memberof.yml b/config/install/field.storage.node.field_memberof.yml similarity index 75% rename from config/install/field.storage.fedora_resource.field_memberof.yml rename to config/install/field.storage.node.field_memberof.yml index aae5dc35..764b3cef 100644 --- a/config/install/field.storage.fedora_resource.field_memberof.yml +++ b/config/install/field.storage.node.field_memberof.yml @@ -6,12 +6,12 @@ dependencies: enforced: module: - islandora -id: fedora_resource.field_memberof +id: node.field_memberof field_name: field_memberof -entity_type: fedora_resource +entity_type: node type: entity_reference settings: - target_type: fedora_resource + target_type: node module: core locked: false cardinality: 1 diff --git a/config/install/field.storage.fedora_resource.field_obj.yml b/config/install/field.storage.node.field_obj.yml similarity index 86% rename from config/install/field.storage.fedora_resource.field_obj.yml rename to config/install/field.storage.node.field_obj.yml index 24716718..a5cbcd38 100644 --- a/config/install/field.storage.fedora_resource.field_obj.yml +++ b/config/install/field.storage.node.field_obj.yml @@ -8,9 +8,9 @@ dependencies: module: - islandora - media_entity -id: fedora_resource.field_obj +id: node.field_obj field_name: field_obj -entity_type: fedora_resource +entity_type: node type: entity_reference settings: target_type: media diff --git a/config/install/field.storage.fedora_resource.field_tn.yml b/config/install/field.storage.node.field_tn.yml similarity index 86% rename from config/install/field.storage.fedora_resource.field_tn.yml rename to config/install/field.storage.node.field_tn.yml index a069ec12..35630fc5 100644 --- a/config/install/field.storage.fedora_resource.field_tn.yml +++ b/config/install/field.storage.node.field_tn.yml @@ -8,9 +8,9 @@ dependencies: enforced: module: - islandora -id: fedora_resource.field_tn +id: node.field_tn field_name: field_tn -entity_type: fedora_resource +entity_type: node type: entity_reference settings: target_type: media diff --git a/config/install/rest.resource.entity.fedora_resource.yml b/config/install/rest.resource.entity.fedora_resource.yml deleted file mode 100644 index f307689c..00000000 --- a/config/install/rest.resource.entity.fedora_resource.yml +++ /dev/null @@ -1,26 +0,0 @@ -uuid: f29f59d6-ed21-46cf-84e2-42141255b0de -langcode: en -status: true -dependencies: - enforced: - module: - - islandora - module: - - islandora - - jsonld - - jwt - - serialization - - user -_core: - default_config_hash: ByaS2KNrlkozt1uLxjOhK6_GNxwV3iIhvXHNqdMZGo8 -id: entity.fedora_resource -plugin_id: 'entity:fedora_resource' -granularity: method -configuration: - GET: - supported_formats: - - jsonld - - json - supported_auth: - - jwt_auth - - cookie diff --git a/config/install/rest.resource.entity.media.yml b/config/install/rest.resource.entity.media.yml index da29fed5..9c52f2e1 100644 --- a/config/install/rest.resource.entity.media.yml +++ b/config/install/rest.resource.entity.media.yml @@ -1,24 +1,27 @@ -uuid: 08836232-8f53-422b-97bd-4394a9660480 +uuid: bf3d7c56-77d9-4154-a7b8-bb77c7188569 langcode: en status: true dependencies: module: + - basic_auth + - hal - jsonld - jwt - media_entity - - serialization - user enforced: module: - islandora id: entity.media plugin_id: 'entity:media' -granularity: method +granularity: resource configuration: - GET: - supported_formats: - - jsonld - - json - supported_auth: - - jwt_auth - - cookie + methods: + - GET + formats: + - hal_json + - jsonld + authentication: + - basic_auth + - jwt_auth + - cookie diff --git a/config/install/rules.reaction.broadcast_create_event.yml b/config/install/rules.reaction.broadcast_content_create_event.yml similarity index 59% rename from config/install/rules.reaction.broadcast_create_event.yml rename to config/install/rules.reaction.broadcast_content_create_event.yml index 542641d3..448a2d9f 100644 --- a/config/install/rules.reaction.broadcast_create_event.yml +++ b/config/install/rules.reaction.broadcast_content_create_event.yml @@ -1,48 +1,43 @@ -uuid: 3ef878c1-3187-4141-aba1-2aac5acc9366 +uuid: b8d1db0c-be8f-47a7-889f-ac710db2e18a langcode: en status: true dependencies: - module: - - islandora - - rules enforced: module: - islandora -_core: - default_config_hash: EKVRKXObBdrm-lGcG3RPpF8sg0tZSZbZx00lkzm42_E -id: broadcast_create_event -label: 'Broadcast Create Event' +id: broadcast_content_create_event +label: 'Broadcast Content Create Event' events: - - event_name: 'rules_entity_insert:fedora_resource' -description: 'Broadcasts a ''Create'' event when a user creates a new FedoraResource.' + event_name: 'rules_entity_insert:node' +description: 'Broadcasts an AS2 event to a message broker when Content is created.' tags: - '' config_version: '3' expression: id: rules_rule - uuid: d25688b0-eef1-46b0-acf4-98a6d1ccd76a + uuid: 40cabb74-fcc7-4498-90f9-3a4ec71b3710 conditions: id: rules_and - uuid: 6648629a-0b52-4352-bb85-df2cbafb7db2 + uuid: 8e0d7b29-15f4-448d-b79a-d85ef97d274e conditions: { } actions: id: rules_action_set - uuid: 957db51c-d055-4350-8caa-4ad773172e87 + uuid: 0f832259-2aa1-45a4-83df-d9e0ff4c7edd actions: - id: rules_action - uuid: d483f5bc-fd36-4d7c-baa4-66234b438d1a + uuid: 922264b9-3db1-42eb-9e01-e781a58a3695 context_values: { } context_mapping: - entity: fedora_resource + entity: node user: '@user.current_user_context:current_user' context_processors: { } provides_mapping: { } action_id: islandora_create_event_generator - id: rules_action - uuid: 2afa7216-91bb-49a3-a567-e504ba8f95e1 + uuid: 0e953790-c751-4de8-99b3-c729ba1e09e3 context_values: recipients: - "activemq:queue:islandora-indexing-fcrepo-create\r" diff --git a/config/install/rules.reaction.broadcast_delete_event.yml b/config/install/rules.reaction.broadcast_content_delete_event.yml similarity index 59% rename from config/install/rules.reaction.broadcast_delete_event.yml rename to config/install/rules.reaction.broadcast_content_delete_event.yml index f021adf4..995fd1ca 100644 --- a/config/install/rules.reaction.broadcast_delete_event.yml +++ b/config/install/rules.reaction.broadcast_content_delete_event.yml @@ -1,48 +1,43 @@ -uuid: 16c10c0c-68a7-4b75-ab8f-ab1778d7c2e2 +uuid: 752003c1-8d98-4d33-b6d3-2bdde52e77bf langcode: en status: true dependencies: - module: - - islandora - - rules enforced: module: - islandora -_core: - default_config_hash: 79mBUbR_0wDo3oT4vWjuFgGPic_hghVkQ0yiYMuxLns -id: broadcast_delete_event -label: 'Broadcast Delete Event' +id: broadcast_content_delete_event +label: 'Broadcast Content Delete Event' events: - - event_name: 'rules_entity_delete:fedora_resource' -description: 'Broadcasts a ''Delete'' event when a user deletes a FedoraResource.' + event_name: 'rules_entity_delete:node' +description: 'Broadcasts an AS2 event to a message broker when Content is deleted.' tags: - '' config_version: '3' expression: id: rules_rule - uuid: dd0ffd15-c6b4-4578-8b54-9c9debae0216 + uuid: b5ca11c1-f80c-4dce-a9f7-9d5db0fec971 conditions: id: rules_and - uuid: 9c50dd1f-ec9a-4cd8-9d18-27c860815a1c + uuid: ede4e2b7-ce4c-4a9d-a5ff-a18a248ccd4c conditions: { } actions: id: rules_action_set - uuid: 7f1f1fc6-d5d2-450b-ba14-225e8e56448f + uuid: 7c96bc08-7b7e-499d-8535-a2c735f6b98b actions: - id: rules_action - uuid: 7ebcda8c-3626-4bff-a536-60caf9f46708 + uuid: 36647c5b-3355-4d4b-8550-5b0170b98ad1 context_values: { } context_mapping: - entity: fedora_resource + entity: node user: '@user.current_user_context:current_user' context_processors: { } provides_mapping: { } action_id: islandora_delete_event_generator - id: rules_action - uuid: 53942d65-7567-4b6b-9b43-4d67079651f6 + uuid: 9257b59c-466c-43d7-8690-62dd87a053eb context_values: recipients: - "activemq:queue:islandora-indexing-fcrepo-delete\r" diff --git a/config/install/rules.reaction.broadcast_update_event.yml b/config/install/rules.reaction.broadcast_content_update_event.yml similarity index 59% rename from config/install/rules.reaction.broadcast_update_event.yml rename to config/install/rules.reaction.broadcast_content_update_event.yml index 98458c7d..b71f287a 100644 --- a/config/install/rules.reaction.broadcast_update_event.yml +++ b/config/install/rules.reaction.broadcast_content_update_event.yml @@ -1,48 +1,43 @@ -uuid: 3bfa9b33-b0a7-437e-a949-e50178a702fe +uuid: 9eeb9a6a-d3ba-41b3-9f1f-68bd016fe8b1 langcode: en status: true dependencies: - module: - - islandora - - rules enforced: module: - islandora -_core: - default_config_hash: XX87LaQzcIVbzZTzUR4HBgeZKCzKOMJzVCTJYgmg47k -id: broadcast_update_event -label: 'Broadcast Update Event' +id: broadcast_content_update_event +label: 'Broadcast Content Update Event' events: - - event_name: 'rules_entity_update:fedora_resource' -description: 'Broadcasts a ''Update'' event when a user updates a FedoraResource.' + event_name: 'rules_entity_update:node' +description: 'Broadcasts an AS2 event to a message broker when Content is updated.' tags: - '' config_version: '3' expression: id: rules_rule - uuid: 55563628-5ea2-4459-989e-0ce573f50aaa + uuid: 55f8a158-3fe4-48bb-92f2-ba53630d56f3 conditions: id: rules_and - uuid: 8113ab9f-7af6-4315-8701-60812bb86190 + uuid: 8269d20f-cb56-4399-8c87-17eb64bfe5eb conditions: { } actions: id: rules_action_set - uuid: 78330180-141b-404e-8bf3-b7c9d8dcc748 + uuid: 567aca08-456f-449e-a91b-b17a21366bdf actions: - id: rules_action - uuid: 86a6f157-8d0c-4b3c-bd8e-d4c3ce4794a7 + uuid: ee51523e-3bba-43a5-95ce-e998fb3392d3 context_values: { } context_mapping: - entity: fedora_resource + entity: node user: '@user.current_user_context:current_user' context_processors: { } provides_mapping: { } action_id: islandora_update_event_generator - id: rules_action - uuid: 40aa4a03-ad36-45bf-9584-ede3b9b3e5c9 + uuid: 7b9cf7be-40e4-4490-ae6f-07a84eb112c4 context_values: recipients: - "activemq:queue:islandora-indexing-fcrepo-update\r" diff --git a/config/install/rules.reaction.broadcast_media_create_event.yml b/config/install/rules.reaction.broadcast_media_create_event.yml index 112007d2..b162bc0c 100644 --- a/config/install/rules.reaction.broadcast_media_create_event.yml +++ b/config/install/rules.reaction.broadcast_media_create_event.yml @@ -1,35 +1,33 @@ -uuid: c4447a0b-a2a8-4f32-947b-fbe1094632d5 +uuid: 4474df44-01ee-4abf-84f9-9aa41d787d27 langcode: en status: true dependencies: enforced: module: - islandora -_core: - default_config_hash: mRt_MC0dKA68qaoXI3WlnCg-ta5Wry0dLR2dpOqY4to id: broadcast_media_create_event label: 'Broadcast Media Create Event' events: - event_name: 'rules_entity_insert:media' -description: 'Broadcasts a ''Create'' event when a user creates a new Media.' +description: 'Broadcasts an AS2 event to a message broker when Media is created.' tags: - '' config_version: '3' expression: id: rules_rule - uuid: 3294a215-25d9-4bfe-9e84-745f381107c5 + uuid: d4ba4cc1-3b18-400d-867f-1605d72d9717 conditions: id: rules_and - uuid: 6dbe3930-7d39-4927-890e-4af4e8fb57fc + uuid: 9ccf9d29-89be-4b1d-8417-230e33f8fd6f conditions: { } actions: id: rules_action_set - uuid: 470ed84d-b33f-4ff4-a584-481605bc826c + uuid: 47afb6b3-e39e-4c3a-af47-669e963353a2 actions: - id: rules_action - uuid: 59b35164-5e52-4664-afe1-86e8f3bda01d + uuid: dff4ebfb-84c5-4d0f-acf7-62e3edbab143 context_values: { } context_mapping: entity: media @@ -39,7 +37,7 @@ expression: action_id: islandora_create_event_generator - id: rules_action - uuid: f7880d70-1411-4c60-a065-a7d187b604db + uuid: 6b0d07b3-048e-43ac-8a9f-2c5203f8080e context_values: recipients: - "activemq:queue:islandora-indexing-triplestore\r" diff --git a/config/install/rules.reaction.broadcast_media_delete_event.yml b/config/install/rules.reaction.broadcast_media_delete_event.yml index 53df0439..5eb15ba3 100644 --- a/config/install/rules.reaction.broadcast_media_delete_event.yml +++ b/config/install/rules.reaction.broadcast_media_delete_event.yml @@ -1,35 +1,33 @@ -uuid: 33b8afa6-1507-4f04-acc9-5a18ca2b0ccc +uuid: 71df1b5d-2f04-42fa-a660-5375de9c6c51 langcode: en status: true dependencies: enforced: module: - islandora -_core: - default_config_hash: Jejr-Hg2lX1o7mdUt_RBxW0xfzOKhoFbGGpepW_SoZg id: broadcast_media_delete_event label: 'Broadcast Media Delete Event' events: - event_name: 'rules_entity_delete:media' -description: 'Broadcasts a ''Delete'' event when a user deletes a Media.' +description: 'Broadcasts an AS2 event to a message broker when Media is deleted.' tags: - '' config_version: '3' expression: id: rules_rule - uuid: 40abb71f-da16-49c3-8646-19921e911b7e + uuid: c12184e7-8230-4bc7-b625-2a26b4a5a913 conditions: id: rules_and - uuid: 34e4e2d6-f6be-4644-ba30-b434b7f2f82b + uuid: 5147d740-4e32-4935-8c30-f893e7c3f86f conditions: { } actions: id: rules_action_set - uuid: 4032fcca-f4ab-471e-afa0-f53e2148848d + uuid: 4a023b99-1cf8-410a-a082-b0c0369a807d actions: - id: rules_action - uuid: 8d9547b4-477d-4442-b8b6-2d677cf79d1d + uuid: 1fdc07dc-72ba-4666-abb8-8d79f29b67ff context_values: { } context_mapping: entity: media @@ -39,7 +37,7 @@ expression: action_id: islandora_delete_event_generator - id: rules_action - uuid: 371b1104-1aa6-4b3d-82cf-e27168e664ae + uuid: 75d0cf84-715b-4167-8ec2-92047a0bec56 context_values: recipients: - "activemq:queue:islandora-indexing-triplestore\r" diff --git a/config/install/rules.reaction.broadcast_media_update_event.yml b/config/install/rules.reaction.broadcast_media_update_event.yml index ea78e3d6..f5a6d292 100644 --- a/config/install/rules.reaction.broadcast_media_update_event.yml +++ b/config/install/rules.reaction.broadcast_media_update_event.yml @@ -1,35 +1,33 @@ -uuid: d58d3327-38d2-400b-91a0-3b00b3870121 +uuid: d5d823ce-cfd0-4e9c-85c9-9090660d831e langcode: en status: true dependencies: enforced: module: - islandora -_core: - default_config_hash: qAkxtz6jH0on_W4QXhpGqZMFfgyATahnUKdynX9bl1g id: broadcast_media_update_event label: 'Broadcast Media Update Event' events: - event_name: 'rules_entity_update:media' -description: 'Broadcasts an ''Update'' event when a user updates a Media.' +description: 'Broadcasts an AS2 event to a message broker when Media is updated.' tags: - '' config_version: '3' expression: id: rules_rule - uuid: 9974766d-92df-4d92-9ba4-e5ae5dce02fd + uuid: 3fb05cc7-f27a-4a79-8e98-544e4aabaf15 conditions: id: rules_and - uuid: faf52a5f-beba-4b09-ac0a-f19f0d23cc52 + uuid: 585b55af-847d-447a-afee-01b855807c4a conditions: { } actions: id: rules_action_set - uuid: 7e0df904-755c-4c89-899b-9bb6212d5c6e + uuid: bb96d589-0d63-4b1b-89d7-faf358171d40 actions: - id: rules_action - uuid: bd3da549-41b5-4d92-9dbd-6dee9d35fadd + uuid: 60a1f348-f85f-45fc-a785-b279b522863a context_values: { } context_mapping: entity: media @@ -39,7 +37,7 @@ expression: action_id: islandora_update_event_generator - id: rules_action - uuid: 6aa1f15c-3a39-4af5-b577-81fa7081de62 + uuid: ee50c8ae-a9cd-479a-aa86-3567629a01b8 context_values: recipients: - "activemq:queue:islandora-indexing-triplestore\r" diff --git a/config/install/views.view.fedora_entities_reference.yml b/config/install/views.view.fedora_entities_reference.yml deleted file mode 100644 index b34cf8e0..00000000 --- a/config/install/views.view.fedora_entities_reference.yml +++ /dev/null @@ -1,169 +0,0 @@ -uuid: ec053572-be63-4209-a49a-16c09c9a3e73 -langcode: en -status: true -dependencies: - module: - - islandora - - user - enforced: - module: - - islandora -_core: - default_config_hash: UU-ZHb4xUJIu4JMAIGXvy0c93Y_xq4CPibq1qrgp098 -id: fedora_entities_reference -label: 'Fedora Entities Reference' -module: views -description: '' -tag: '' -base_table: fedora_resource_field_data -base_field: id -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: default - row: - type: fields - fields: - name: - id: name - table: fedora_resource_field_data - field: name - entity_type: fedora_resource - entity_field: name - label: '' - alter: - alter_text: false - make_link: false - absolute: false - trim: false - word_boundary: false - ellipsis: false - strip_tags: false - html: false - hide_empty: false - empty_zero: false - settings: - link_to_entity: true - plugin_id: field - relationship: none - group_type: group - admin_label: '' - exclude: 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_alter_empty: true - click_sort_column: value - type: string - 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 - filters: - status: - value: '1' - table: fedora_resource_field_data - field: status - plugin_id: boolean - entity_type: fedora_resource - entity_field: status - id: status - expose: - operator: '' - group: 1 - sorts: { } - title: 'Bundles of Fedora' - header: { } - footer: { } - empty: { } - relationships: { } - arguments: { } - display_extenders: { } - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - url.query_args - - user.permissions - tags: { } - entity_reference_1: - display_plugin: entity_reference - id: entity_reference_1 - display_title: 'All Fedora Resource Entities' - position: 2 - display_options: - display_extenders: { } - style: - type: entity_reference - options: - search_fields: - name: name - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - user.permissions - tags: { } diff --git a/config/install/views.view.membership_view.yml b/config/install/views.view.membership_view.yml deleted file mode 100644 index e9ad9e02..00000000 --- a/config/install/views.view.membership_view.yml +++ /dev/null @@ -1,216 +0,0 @@ -uuid: 84f7671f-475f-4b91-98d5-42182389414c -langcode: en -status: true -dependencies: - config: - - core.entity_view_mode.fedora_resource.teaser - enforced: - module: - - islandora - module: - - islandora - - user -_core: - default_config_hash: he4YnarZrhrqUnqtFXImn2pESaJQdTTWmFPyapSRwoM -id: membership_view -label: 'Membership View' -module: views -description: 'Displays a list of member resources' -tag: '' -base_table: fedora_resource_field_data -base_field: id -core: 8.x -display: - default: - display_plugin: default - id: default - display_title: Master - position: 0 - display_options: - access: - type: perm - options: - perm: 'view published fedora resource entities' - 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: default - options: - row_class: '' - default_row_class: true - uses_fields: false - row: - type: 'entity:fedora_resource' - options: - relationship: none - view_mode: teaser - fields: - name: - id: name - table: fedora_resource_field_data - field: name - entity_type: fedora_resource - entity_field: name - label: '' - alter: - alter_text: false - make_link: false - absolute: false - trim: false - word_boundary: false - ellipsis: false - strip_tags: false - html: false - hide_empty: false - empty_zero: false - settings: - link_to_entity: true - plugin_id: field - relationship: none - group_type: group - admin_label: '' - exclude: 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_alter_empty: true - click_sort_column: value - type: string - 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 - filters: { } - sorts: { } - header: { } - footer: { } - empty: { } - relationships: { } - arguments: - field_memberof_target_id: - id: field_memberof_target_id - table: fedora_resource__field_memberof - field: field_memberof_target_id - relationship: none - group_type: group - admin_label: '' - default_action: empty - exception: - value: all - title_enable: false - title: All - title_enable: false - title: '' - default_argument_type: fixed - default_argument_options: - argument: '' - default_argument_skip_url: false - summary_options: - base_path: '' - count: true - items_per_page: 25 - override: false - summary: - sort_order: asc - number_of_records: 0 - format: default_summary - specify_validation: false - validate: - type: none - fail: 'not found' - validate_options: { } - break_phrase: false - not: false - plugin_id: numeric - display_extenders: { } - title: Members - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - url - - url.query_args - - user.permissions - tags: { } - page: - display_plugin: page - id: page - display_title: Members - position: 2 - display_options: - display_extenders: { } - path: fedora_resource/%fedora_resource/members - menu: - type: tab - title: Members - description: 'A list of members of this resource' - expanded: false - parent: '' - weight: -1 - context: '0' - menu_name: main - tab_options: - type: none - title: '' - description: '' - weight: 0 - display_description: 'Members of {{ name }}' - cache_metadata: - max-age: -1 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - url - - url.query_args - - user.permissions - tags: { } diff --git a/config/schema/fedora_resource_type.schema.yml b/config/schema/fedora_resource_type.schema.yml deleted file mode 100644 index cde84179..00000000 --- a/config/schema/fedora_resource_type.schema.yml +++ /dev/null @@ -1,24 +0,0 @@ -islandora.fedora_resource_type.*: - type: config_entity - label: 'Fedora resource type config' - mapping: - id: - type: string - label: 'ID' - label: - type: label - label: 'Label' - uuid: - type: string - -# Plugin \Drupal\islandora\Plugin\Search\FedoraResourceSearch -search.plugin.node_search: - type: mapping - label: 'Fedora Resource search' - mapping: - rankings: - type: sequence - label: 'Content ranking' - sequence: - type: integer - label: 'Influence' diff --git a/fedora_resource.page.inc b/fedora_resource.page.inc deleted file mode 100644 index dfa7f9f6..00000000 --- a/fedora_resource.page.inc +++ /dev/null @@ -1,71 +0,0 @@ - https://github.com/diegopino - */ - -use Drupal\Core\Render\Element; -use Drupal\Core\Link; -use Drupal\Core\Url; - -/** - * Prepares variables for Fedora resource templates. - * - * Default template: fedora_resource.html.twig. - * - * @param array $variables - * An associative array containing: - * - elements: An associative array containing the user information and any - * - attributes: HTML attributes for the containing element. - */ -function template_preprocess_fedora_resource(array &$variables) { - // Fetch FedoraResource Entity Object. - $fedora_resource = $variables['elements']['#fedora_resource']; - - // Helpful $content variable for templates. - foreach (Element::children($variables['elements']) as $key) { - $variables['content'][$key] = $variables['elements'][$key]; - } -} - -/** - * Prepares variables for a custom entity type creation list templates. - * - * Default template: fedora_resource-content-add-list.html.twig. - * - * @param array $variables - * An associative array containing: - * - content: An array of fedora_resource-types. - * - * @see block_content_add_page() - */ -function template_preprocess_fedora_resource_content_add_list(array &$variables) { - $variables['types'] = []; - $query = \Drupal::request()->query->all(); - foreach ($variables['content'] as $type) { - $variables['types'][$type->id()] = [ - 'link' => Link::fromTextAndUrl($type->label(), new Url('entity.fedora_resource.add_form', [ - 'fedora_resource_type' => $type->id(), - ], ['query' => $query])), - 'description' => [ - '#markup' => $type->label(), - ], - 'title' => $type->label(), - 'localized_options' => [ - 'query' => $query, - ], - ]; - } -} diff --git a/islandora.install b/islandora.install index e900f2f6..351111df 100644 --- a/islandora.install +++ b/islandora.install @@ -5,6 +5,8 @@ * Install/update hook implementations. */ +use Drupal\rest\Entity\RestResourceConfig; + /** * Implements hook_schema(). */ @@ -40,3 +42,19 @@ function islandora_schema() { ]; return $schema; } + +/** + * Implemets hook_install(). + */ +function islandora_install() { + $rest_config = RestResourceConfig::load('entity.node'); + + $configuration = [ + 'methods' => ['GET', 'POST', 'PATCH', 'DELETE'], + 'formats' => ['hal_json', 'jsonld'], + 'authentication' => ['basic_auth', 'jwt_auth', 'cookie'], + ]; + + $rest_config->set('configuration', $configuration); + $rest_config->save(TRUE); +} diff --git a/islandora.links.action.yml b/islandora.links.action.yml deleted file mode 100644 index 2aa6bf43..00000000 --- a/islandora.links.action.yml +++ /dev/null @@ -1,10 +0,0 @@ -entity.fedora_resource.add_form: - route_name: 'fedora_resource.add_page' - title: 'Add Fedora resource' - appears_on: - - entity.fedora_resource.collection -entity.fedora_resource_type.add_form: - route_name: 'entity.fedora_resource_type.add_form' - title: 'Add Fedora resource type' - appears_on: - - entity.fedora_resource_type.collection diff --git a/islandora.links.menu.yml b/islandora.links.menu.yml index 68f3f79b..36024a19 100644 --- a/islandora.links.menu.yml +++ b/islandora.links.menu.yml @@ -1,11 +1,3 @@ -# Fedora resource type menu items definition -entity.fedora_resource_type.collection: - title: 'Fedora resource type list' - route_name: entity.fedora_resource_type.collection - description: 'List Fedora resource type (bundles)' - parent: system.admin_structure - weight: 99 - # Menu list of Islandora configuration forms system.admin_config_islandora: title: Islandora diff --git a/islandora.links.task.yml b/islandora.links.task.yml deleted file mode 100644 index e3096748..00000000 --- a/islandora.links.task.yml +++ /dev/null @@ -1,21 +0,0 @@ -# Fedora resource routing definition -entity.fedora_resource.canonical: - route_name: entity.fedora_resource.canonical - base_route: entity.fedora_resource.canonical - title: 'View' - -entity.fedora_resource.edit_form: - route_name: entity.fedora_resource.edit_form - base_route: entity.fedora_resource.canonical - title: Edit - -entity.fedora_resource.delete_form: - route_name: entity.fedora_resource.delete_form - base_route: entity.fedora_resource.canonical - title: Delete - weight: 10 - -entity.fedora_resource.collection: - route_name: entity.fedora_resource.collection - base_route: system.admin_content - title: 'Fedora Resources' diff --git a/islandora.module b/islandora.module index fb9dd0c1..e33cb44d 100644 --- a/islandora.module +++ b/islandora.module @@ -34,40 +34,6 @@ function islandora_help($route_name, RouteMatchInterface $route_match) { } } -/** - * Implements hook_theme(). - */ -function islandora_theme() { - $theme = []; - $theme['fedora_resource'] = [ - 'render element' => 'elements', - 'file' => 'fedora_resource.page.inc', - 'template' => 'fedora_resource', - ]; - $theme['fedora_resource_content_add_list'] = [ - 'render element' => 'content', - 'variables' => ['content' => NULL], - 'file' => 'fedora_resource.page.inc', - ]; - return $theme; -} - -/** - * Implements hook_theme_suggestions_HOOK(). - */ -function islandora_theme_suggestions_fedora_resource(array $variables) { - $suggestions = []; - $entity = $variables['elements']['#fedora_resource']; - $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); - - $suggestions[] = 'fedora_resource__' . $sanitized_view_mode; - $suggestions[] = 'fedora_resource__' . $entity->bundle(); - $suggestions[] = 'fedora_resource__' . $entity->bundle() . '__' . $sanitized_view_mode; - $suggestions[] = 'fedora_resource__' . $entity->id(); - $suggestions[] = 'fedora_resource__' . $entity->id() . '__' . $sanitized_view_mode; - return $suggestions; -} - /** * Implements hook_rdf_namespaces(). */ @@ -92,7 +58,7 @@ function islandora_rdf_namespaces() { /** * Implements hook_ENTITY_TYPE_insert(). */ -function islandora_fedora_resource_insert(EntityInterface $entity) { +function islandora_node_insert(EntityInterface $entity) { // Creates a record in the db to track the number of changes to the entity. $versionCounter = \Drupal::service('islandora.versioncounter'); try { @@ -110,7 +76,7 @@ function islandora_fedora_resource_insert(EntityInterface $entity) { /** * Implements hook_ENTITY_TYPE_update(). */ -function islandora_fedora_resource_update(EntityInterface $entity) { +function islandora_node_update(EntityInterface $entity) { // Increments the number of changes to the entity. $versionCounter = \Drupal::service('islandora.versioncounter'); $versionCounter->increment($entity->uuid()); @@ -119,7 +85,7 @@ function islandora_fedora_resource_update(EntityInterface $entity) { /** * Implements hook_ENTITY_TYPE_update(). */ -function islandora_fedora_resource_delete(EntityInterface $entity) { +function islandora_node_delete(EntityInterface $entity) { // Deletes the record in the db to track the number of changes to the entity. $versionCounter = \Drupal::service('islandora.versioncounter'); $versionCounter->delete($entity->uuid()); diff --git a/islandora.permissions.yml b/islandora.permissions.yml deleted file mode 100644 index e1fc0a80..00000000 --- a/islandora.permissions.yml +++ /dev/null @@ -1,26 +0,0 @@ -# Fedora Resource permissions -add fedora resource entities: - title: 'Create new Fedora resource entities' - -administer fedora resource entities: - title: 'Administer Fedora resource entities' - description: 'Allow to access the administration form to configure Fedora resource entities.' - restrict access: true - -delete fedora resource entities: - title: 'Delete Fedora resource entities' - -edit fedora resource entities: - title: 'Edit Fedora resource entities' - -view published fedora resource entities: - title: 'View published Fedora resource entities' - -view unpublished fedora resource entities: - title: 'View unpublished Fedora resource entities' - -# Fedora Resource Type permissions -administer fedora resource type entities: - title: 'Administer Fedora Resource Type entities' - description: 'Allow to access administration of Fedora Resource Type entities (bundles).' - restrict access: true diff --git a/islandora.routing.yml b/islandora.routing.yml index e264e339..d7963c65 100644 --- a/islandora.routing.yml +++ b/islandora.routing.yml @@ -17,13 +17,9 @@ system.islandora_settings: _permission: 'administer site configuration' # Islandora JSON-LD Routing definition -entity.fedora_resource_type.jsonldcontext: - path: '/fedora_resource_context/{bundle}' +islandora.jsonldcontext: + path: '/context/{entity_type}/{bundle}' defaults: - _controller: '\Drupal\islandora\Controller\FedoraResourceJsonLdContextController::content' + _controller: '\Drupal\islandora\Controller\JsonLdContextController::content' requirements: _permission: 'access content' - options: - parameters: - bundle: - type: entity:{fedora_resource}:{fedora_resource_type} diff --git a/src/Controller/FedoraResourceAddController.php b/src/Controller/FedoraResourceAddController.php deleted file mode 100644 index 782b21c7..00000000 --- a/src/Controller/FedoraResourceAddController.php +++ /dev/null @@ -1,119 +0,0 @@ -storage = $storage; - $this->typeStorage = $type_storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - /** @var EntityTypeManagerInterface $entity_type_manager */ - $entity_type_manager = $container->get('entity_type.manager'); - return new static( - $entity_type_manager->getStorage('fedora_resource'), - $entity_type_manager->getStorage('fedora_resource_type') - ); - } - - /** - * Displays add links for available bundles/types for entity fedora_resource. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request object. - * - * @return array - * A render array for a list of the fedora_resource bundles/types that can - * be added or if there is only one type/bunlde defined for the site, the - * function returns the add page for that bundle/type. - */ - public function add(Request $request) { - $types = $this->typeStorage->loadMultiple(); - if ($types && count($types) == 1) { - $type = reset($types); - return $this->addForm($type, $request); - } - if (count($types) === 0) { - return [ - '#markup' => $this->t('You have not created any %bundle types yet. @link to add a new type.', [ - '%bundle' => 'Fedora resource', - '@link' => $this->l($this->t('Go to the type creation page'), Url::fromRoute('entity.fedora_resource_type.add_form')), - ]), - ]; - } - return ['#theme' => 'fedora_resource_content_add_list', '#content' => $types]; - } - - /** - * Presents the creation form for fedora_resource entities of given type. - * - * @param \Drupal\Core\Entity\EntityInterface $fedora_resource_type - * The custom bundle to add. - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request object. - * - * @return array - * A form array as expected by drupal_render(). - */ - public function addForm(EntityInterface $fedora_resource_type, Request $request) { - $entity = $this->storage->create([ - 'type' => $fedora_resource_type->id(), - ]); - return $this->entityFormBuilder()->getForm($entity); - } - - /** - * Provides the page title for this controller. - * - * @param \Drupal\Core\Entity\EntityInterface $fedora_resource_type - * The custom bundle/type being added. - * - * @return string - * The page title. - */ - public function getAddFormTitle(EntityInterface $fedora_resource_type) { - return t('Create of bundle @label', - ['@label' => $fedora_resource_type->label()] - ); - } - -} diff --git a/src/Controller/FedoraResourceJsonLdContextController.php b/src/Controller/JsonLdContextController.php similarity index 83% rename from src/Controller/FedoraResourceJsonLdContextController.php rename to src/Controller/JsonLdContextController.php index 77c41ac0..abb093fb 100644 --- a/src/Controller/FedoraResourceJsonLdContextController.php +++ b/src/Controller/JsonLdContextController.php @@ -13,11 +13,11 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableMetadata; /** - * Class FedoraResourceJsonLdContextController. + * Class JsonLdContextController. * * @package Drupal\islandora\Controller */ -class FedoraResourceJsonLdContextController extends ControllerBase { +class JsonLdContextController extends ControllerBase { /** * Injected JsonldContextGenerator. @@ -27,7 +27,7 @@ class FedoraResourceJsonLdContextController extends ControllerBase { private $jsonldContextGenerator; /** - * FedoraResourceJsonLdContextController constructor. + * JsonLdContextController constructor. * * @param \Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface $jsonld_context_generator * Injected JsonldContextGenerator. @@ -50,8 +50,10 @@ class FedoraResourceJsonLdContextController extends ControllerBase { } /** - * Returns an JSON-LD Context for a fedora_resource bundle. + * Returns an JSON-LD Context for a entity bundle. * + * @param string $entity_type + * Route argument, an entity type. * @param string $bundle * Route argument, a bundle. * @param \Symfony\Component\HttpFoundation\Request $request @@ -60,12 +62,12 @@ class FedoraResourceJsonLdContextController extends ControllerBase { * @return \Symfony\Component\HttpFoundation\Response * An Http response. */ - public function content($bundle, Request $request) { + public function content($entity_type, $bundle, Request $request) { // TODO: expose cached/not cached through // more varied HTTP response codes. try { - $context = $this->jsonldContextGenerator->getContext('fedora_resource.' . $bundle); + $context = $this->jsonldContextGenerator->getContext("$entity_type.$bundle"); $response = new CacheableJsonResponse(json_decode($context), 200); $response->setEncodingOptions(JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK); $response->headers->set('X-Powered-By', 'Islandora CLAW API'); @@ -74,7 +76,7 @@ class FedoraResourceJsonLdContextController extends ControllerBase { // For now deal with Cache dependencies manually. $meta = new CacheableMetadata(); $meta->setCacheContexts(['user.permissions', 'ip', 'url']); - $meta->setCacheTags(RdfMapping::load('fedora_resource.' . $bundle)->getCacheTags()); + $meta->setCacheTags(RdfMapping::load("$entity_type.$bundle")->getCacheTags()); $meta->setCacheMaxAge(Cache::PERMANENT); $response->addCacheableDependency($meta); } diff --git a/src/Entity/FedoraResource.php b/src/Entity/FedoraResource.php deleted file mode 100644 index 7fa63146..00000000 --- a/src/Entity/FedoraResource.php +++ /dev/null @@ -1,465 +0,0 @@ -getEntityTypeId()] = $this->uuid(); - } - return $uri_route_parameters; - - } - - /** - * {@inheritdoc} - */ - public static function preCreate(EntityStorageInterface $storage_controller, array &$values) { - parent::preCreate($storage_controller, $values); - $values += [ - 'user_id' => \Drupal::currentUser()->id(), - ]; - } - - /** - * {@inheritdoc} - */ - public function postSave(EntityStorageInterface $storage, $update = TRUE) { - parent::postSave($storage, $update); - - // Reindex the entity when it is updated. The entity is automatically - // indexed when it is added, simply by being added to the {fedora_resource} - // table. Only required if using the core search index. - if ($update) { - if (\Drupal::moduleHandler()->moduleExists('search')) { - search_mark_for_reindex('fedora_resource_search', $this->id()); - } - } - } - - /** - * {@inheritdoc} - */ - public static function postDelete(EntityStorageInterface $storage, array $entities) { - parent::postDelete($storage, $entities); - - // This removes references to deleted parents. But this could be - // used to remove child entities instead. - foreach ($entities as $entity) { - if ($entity->getEntityType()->getBundleEntityType() == 'fedora_resource_type') { - $references = self::getInboundReferences($entity); - if ($references) { - $ref_entities = $storage->loadMultiple($references); - foreach ($ref_entities as $ref_entity) { - $ref_entity->removeParent(); - $ref_entity->save(); - } - } - } - } - } - - /** - * {@inheritdoc} - */ - public function getType() { - return $this->bundle(); - } - - /** - * {@inheritdoc} - */ - public function getName() { - return $this->get('name')->value; - } - - /** - * {@inheritdoc} - */ - public function setName($name) { - $this->set('name', $name); - return $this; - } - - /** - * {@inheritdoc} - */ - public function getCreatedTime() { - return $this->get('created')->value; - } - - /** - * {@inheritdoc} - */ - public function setCreatedTime($timestamp) { - $this->set('created', $timestamp); - return $this; - } - - /** - * {@inheritdoc} - */ - public function getOwner() { - return $this->get('user_id')->entity; - } - - /** - * {@inheritdoc} - */ - public function getOwnerId() { - return $this->get('user_id')->target_id; - } - - /** - * {@inheritdoc} - */ - public function setOwnerId($uid) { - $this->set('user_id', $uid); - return $this; - } - - /** - * {@inheritdoc} - */ - public function setOwner(UserInterface $account) { - $this->set('user_id', $account->id()); - return $this; - } - - /** - * {@inheritdoc} - */ - public function isPublished() { - return (bool) $this->getEntityKey('status'); - } - - /** - * {@inheritdoc} - */ - public function setPublished($published) { - $this->set('status', $published ? NODE_PUBLISHED : NODE_NOT_PUBLISHED); - return $this; - } - - /** - * {@inheritdoc} - */ - public function hasParent() { - return (!$this->get('fedora_has_parent')->isEmpty()); - } - - /** - * {@inheritdoc} - */ - public function getParent() { - return $this->get('fedora_has_parent') - ->first() - ->get('entity') - ->getTarget() - ->getValue(); - } - - /** - * {@inheritdoc} - */ - public function getParentId() { - return $this->get('fedora_has_parent') - ->first() - ->get('entity') - ->getTarget() - ->getValue() - ->id(); - } - - /** - * {@inheritdoc} - */ - public function setParent(FedoraResourceInterface $entity) { - $this->set('fedora_has_parent', $entity); - return $this; - } - - /** - * {@inheritdoc} - */ - public function removeParent() { - $this->set('fedora_has_parent', NULL); - return $this; - } - - /** - * Default value callback for 'fedora_has_parent' base field definition. - * - * @see ::baseFieldDefinitions() - * - * @return array - * An array of default values. - */ - public static function getFedoraRoot() { - // Just stub code, we need to figure out what "root is" in this context. - return NULL; - } - - /** - * Get all the objects that have $entity as a fedora_has_parent. - * - * @param \Drupal\islandora\FedoraResourceInterface $entity - * The entity to find inbound references for. - * - * @return array - * An array of entity ids - */ - protected static function getInboundReferences(FedoraResourceInterface $entity) { - // TODO: Not use static loading. - $query = \Drupal::entityQuery('fedora_resource'); - $query->condition('fedora_has_parent', $entity->id()); - return $query->execute(); - } - - /** - * {@inheritdoc} - */ - public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - $fields['id'] = BaseFieldDefinition::create('integer') - ->setLabel(t('ID')) - ->setDescription(t('The ID of the Fedora resource entity.')) - ->setReadOnly(TRUE); - $fields['vid'] = BaseFieldDefinition::create('integer') - ->setLabel(t('Revision ID')) - ->setDescription(t('The Fedora resource revision ID.')) - ->setReadOnly(TRUE) - ->setSetting('unsigned', TRUE); - $fields['type'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Type')) - ->setDescription(t('The Fedora resource type/bundle.')) - ->setSetting('target_type', 'fedora_resource_type') - ->setRequired(TRUE); - $fields['uuid'] = BaseFieldDefinition::create('uuid') - ->setLabel(t('UUID')) - ->setDescription(t('The UUID of the Fedora resource entity.')) - ->setReadOnly(TRUE); - - $fields['user_id'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Authored by')) - ->setDescription(t('The user ID of author of the Fedora resource entity.')) - ->setRevisionable(TRUE) - ->setSetting('target_type', 'user') - ->setSetting('handler', 'default') - ->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId') - ->setTranslatable(TRUE) - ->setDisplayOptions('view', [ - 'label' => 'hidden', - 'type' => 'author', - 'weight' => 0, - ]) - ->setDisplayOptions('form', [ - 'type' => 'entity_reference_autocomplete', - 'weight' => 5, - 'settings' => [ - 'match_operator' => 'CONTAINS', - 'size' => '60', - 'autocomplete_type' => 'tags', - 'placeholder' => '', - ], - ]) - ->setDisplayConfigurable('form', TRUE) - ->setDisplayConfigurable('view', TRUE); - - // Removing from form and display until we get behaviour sorted out. - $fields['fedora_has_parent'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Fedora has Parent')) - ->setDescription(t('Parent Fedora Resource.')) - ->setRevisionable(TRUE) - ->setSetting('target_type', 'fedora_resource') - ->setSetting('handler', 'default') - ->setDefaultValueCallback('\Drupal\islandora\Entity\FedoraResource::getFedoraRoot') - ->setTranslatable(TRUE) - ->setDisplayConfigurable('form', FALSE) - ->setDisplayConfigurable('view', FALSE); - - $fields['name'] = BaseFieldDefinition::create('string') - ->setLabel(t('Name')) - ->setDescription(t('The name of the Fedora resource entity.')) - ->setSettings([ - 'max_length' => 50, - 'text_processing' => 0, - ]) - ->setDefaultValue('') - ->setDisplayOptions('view', [ - 'label' => 'above', - 'type' => 'string', - 'weight' => -4, - ]) - ->setDisplayOptions('form', [ - 'type' => 'string_textfield', - 'weight' => -4, - ]) - ->setDisplayConfigurable('form', TRUE) - ->setDisplayConfigurable('view', TRUE); - - $fields['status'] = BaseFieldDefinition::create('boolean') - ->setLabel(t('Publishing status')) - ->setDescription(t('A boolean indicating whether the Fedora resource is published.')) - ->setDefaultValue(TRUE); - - $fields['langcode'] = BaseFieldDefinition::create('language') - ->setLabel(t('Language code')) - ->setDescription(t('The language code for the Fedora resource entity.')) - ->setDisplayOptions('form', [ - 'type' => 'language_select', - 'weight' => 10, - ]) - ->setDisplayConfigurable('form', TRUE); - - $fields['created'] = BaseFieldDefinition::create('created') - ->setLabel(t('Created')) - ->setDescription(t('The time that the entity was created.')); - - $fields['changed'] = BaseFieldDefinition::create('changed') - ->setLabel(t('Changed')) - ->setDescription(t('The time that the entity was last edited.')); - - $fields['promote'] = BaseFieldDefinition::create('boolean') - ->setLabel(t('Promoted to front page')) - ->setRevisionable(TRUE) - ->setTranslatable(TRUE) - ->setDefaultValue(TRUE) - ->setDisplayOptions('form', [ - 'type' => 'boolean_checkbox', - 'settings' => [ - 'display_label' => TRUE, - ], - 'weight' => 15, - ]) - ->setDisplayConfigurable('form', TRUE); - - $fields['sticky'] = BaseFieldDefinition::create('boolean') - ->setLabel(t('Sticky at top of lists')) - ->setRevisionable(TRUE) - ->setTranslatable(TRUE) - ->setDefaultValue(FALSE) - ->setDisplayOptions('form', [ - 'type' => 'boolean_checkbox', - 'settings' => [ - 'display_label' => TRUE, - ], - 'weight' => 16, - ]) - ->setDisplayConfigurable('form', TRUE); - - $fields['revision_timestamp'] = BaseFieldDefinition::create('created') - ->setLabel(t('Revision timestamp')) - ->setDescription(t('The time that the current revision was created.')) - ->setQueryable(FALSE) - ->setRevisionable(TRUE); - - $fields['revision_uid'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Revision user ID')) - ->setDescription(t('The user ID of the author of the current revision.')) - ->setSetting('target_type', 'user') - ->setQueryable(FALSE) - ->setRevisionable(TRUE); - - $fields['revision_log'] = BaseFieldDefinition::create('string_long') - ->setLabel(t('Revision log message')) - ->setDescription(t('Briefly describe the changes you have made.')) - ->setRevisionable(TRUE) - ->setDefaultValue('') - ->setDisplayOptions('form', [ - 'type' => 'string_textarea', - 'weight' => 25, - 'settings' => [ - 'rows' => 4, - ], - ]); - - $fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean') - ->setLabel(t('Revision translation affected')) - ->setDescription(t('Indicates if the last edit of a translation belongs to current revision.')) - ->setReadOnly(TRUE) - ->setRevisionable(TRUE) - ->setTranslatable(TRUE); - return $fields; - } - -} diff --git a/src/Entity/FedoraResourceType.php b/src/Entity/FedoraResourceType.php deleted file mode 100644 index a777c563..00000000 --- a/src/Entity/FedoraResourceType.php +++ /dev/null @@ -1,57 +0,0 @@ - 'id', - 'title' => $this->t('Fedora resource'), - 'help' => $this->t('The Fedora resource ID.'), - ]; - - $data['fedora_resource_field_data']['table']['wizard_id'] = 'fedora_resource'; - $data['fedora_resource_field_revision']['table']['wizard_id'] = 'fedora_resource_revision'; - - return $data; - } - -} diff --git a/src/FedoraResourceAccessControlHandler.php b/src/FedoraResourceAccessControlHandler.php deleted file mode 100644 index bb4f9e12..00000000 --- a/src/FedoraResourceAccessControlHandler.php +++ /dev/null @@ -1,48 +0,0 @@ -isPublished()) { - return AccessResult::allowedIfHasPermission($account, 'view unpublished fedora resource entities'); - } - return AccessResult::allowedIfHasPermission($account, 'view published fedora resource entities'); - - case 'update': - return AccessResult::allowedIfHasPermission($account, 'edit fedora resource entities'); - - case 'delete': - return AccessResult::allowedIfHasPermission($account, 'delete fedora resource entities'); - } - - // Unknown operation, no opinion. - return AccessResult::neutral(); - } - - /** - * {@inheritdoc} - */ - protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return AccessResult::allowedIfHasPermission($account, 'add fedora resource entities'); - } - -} diff --git a/src/FedoraResourceHtmlRouteProvider.php b/src/FedoraResourceHtmlRouteProvider.php deleted file mode 100644 index 30e689f1..00000000 --- a/src/FedoraResourceHtmlRouteProvider.php +++ /dev/null @@ -1,184 +0,0 @@ -id(); - - if ($collection_route = $this->getCollectionRoute($entity_type)) { - $collection->add("entity.{$entity_type_id}.collection", $collection_route); - } - - if ($add_form_route = $this->getAddFormRoute($entity_type)) { - $collection->add("entity.{$entity_type_id}.add_form", $add_form_route); - } - - $add_page_route = $this->getAddPageRoute($entity_type); - $collection->add("$entity_type_id.add_page", $add_page_route); - - if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) { - $collection->add("$entity_type_id.settings", $settings_form_route); - } - - if ($uuid_route = $this->getUuidRoute($entity_type)) { - $collection->add("entity.{$entity_type_id}.uuid", $uuid_route); - } - - return $collection; - } - - /** - * Gets the UUID route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getUuidRoute(EntityTypeInterface $entity_type) { - if ($entity_type->getKey('uuid') && $entity_type->hasViewBuilderClass() && $entity_type->hasLinkTemplate('uuid')) { - $entity_type_id = $entity_type->id(); - $route = new Route($entity_type->getLinkTemplate('uuid')); - $route - ->addDefaults([ - '_entity_view' => "{$entity_type_id}.full", - '_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title', - ]) - ->setRequirement('_entity_access', "{$entity_type_id}.view") - ->setOption('parameters', [ - $entity_type_id => ['type' => "uuid"], - ]) - // Fetch UUID pattern from Uuid class(constant) - ->setRequirement($entity_type_id, '^' . Uuid::VALID_PATTERN . '$'); - return $route; - } - } - - /** - * Gets the collection route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getCollectionRoute(EntityTypeInterface $entity_type) { - if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) { - $entity_type_id = $entity_type->id(); - $route = new Route($entity_type->getLinkTemplate('collection')); - $route - ->setDefaults([ - '_entity_list' => $entity_type_id, - '_title' => "{$entity_type->getLabel()} list", - ]) - ->setRequirement('_permission', 'view fedora resource entities') - ->setOption('_admin_route', TRUE); - - return $route; - } - } - - /** - * Gets the add-form route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getAddFormRoute(EntityTypeInterface $entity_type) { - if ($entity_type->hasLinkTemplate('add-form')) { - $entity_type_id = $entity_type->id(); - $parameters = [ - $entity_type_id => ['type' => 'entity:' . $entity_type_id], - ]; - - $route = new Route($entity_type->getLinkTemplate('add-form')); - $bundle_entity_type_id = $entity_type->getBundleEntityType(); - // Content entities with bundles are added via a dedicated controller. - $route - ->setDefaults([ - '_controller' => 'Drupal\islandora\Controller\FedoraResourceAddController::addForm', - '_title_callback' => 'Drupal\islandora\Controller\FedoraResourceAddController::getAddFormTitle', - ]) - ->setRequirement('_entity_create_access', $entity_type_id . ':{' . $bundle_entity_type_id . '}'); - $parameters[$bundle_entity_type_id] = ['type' => 'entity:' . $bundle_entity_type_id]; - - $route - ->setOption('parameters', $parameters) - ->setOption('_admin_route', TRUE); - - return $route; - } - } - - /** - * Gets the add page route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getAddPageRoute(EntityTypeInterface $entity_type) { - $route = new Route("/admin/structure/{$entity_type->id()}/add"); - $route - ->setDefaults([ - '_controller' => 'Drupal\islandora\Controller\FedoraResourceAddController::add', - '_title' => "Add {$entity_type->getLabel()}", - ]) - ->setRequirement('_entity_create_access', $entity_type->id()) - ->setOption('_admin_route', TRUE); - - return $route; - } - - /** - * Gets the settings form route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getSettingsFormRoute(EntityTypeInterface $entity_type) { - if (!$entity_type->getBundleEntityType()) { - $route = new Route("/admin/structure/{$entity_type->id()}/settings"); - $route - ->setDefaults([ - '_form' => 'Drupal\islandora\Form\FedoraResourceSettingsForm', - '_title' => "{$entity_type->getLabel()} settings", - ]) - ->setRequirement('_permission', $entity_type->getAdminPermission()) - ->setOption('_admin_route', TRUE); - - return $route; - } - } - -} diff --git a/src/FedoraResourceInterface.php b/src/FedoraResourceInterface.php deleted file mode 100644 index c7b472f2..00000000 --- a/src/FedoraResourceInterface.php +++ /dev/null @@ -1,119 +0,0 @@ -t('Fedora resource ID'); - $header['name'] = $this->t('Name'); - $header['parent'] = $this->t('Parent'); - return $header + parent::buildHeader(); - } - - /** - * {@inheritdoc} - */ - public function buildRow(EntityInterface $entity) { - /* @var $entity \Drupal\islandora\Entity\FedoraResource */ - $row['id'] = $entity->id(); - $row['name'] = Link::fromTextAndUrl( - $entity->label(), - $entity->toUrl() - ); - if ($entity->hasParent()) { - $row['parent'] = Link::fromTextAndUrl( - $entity->getParent()->label(), - $entity->getParent()->toUrl() - ); - } - else { - $row['parent'] = $this->t("n/a"); - } - return $row + parent::buildRow($entity); - } - -} diff --git a/src/FedoraResourceTypeHtmlRouteProvider.php b/src/FedoraResourceTypeHtmlRouteProvider.php deleted file mode 100644 index 38e54a0d..00000000 --- a/src/FedoraResourceTypeHtmlRouteProvider.php +++ /dev/null @@ -1,97 +0,0 @@ -id(); - - if ($collection_route = $this->getCollectionRoute($entity_type)) { - $collection->add("entity.{$entity_type_id}.collection", $collection_route); - } - - if ($add_form_route = $this->getAddFormRoute($entity_type)) { - $collection->add("entity.{$entity_type_id}.add_form", $add_form_route); - } - - return $collection; - } - - /** - * Gets the collection route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getCollectionRoute(EntityTypeInterface $entity_type) { - if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) { - $entity_type_id = $entity_type->id(); - $route = new Route($entity_type->getLinkTemplate('collection')); - $route - ->setDefaults([ - '_entity_list' => $entity_type_id, - // Make sure this is not a TranslatableMarkup object as the - // TitleResolver translates this string again. - '_title' => (string) $entity_type->getLabel(), - ]) - ->setRequirement('_permission', $entity_type->getAdminPermission()) - ->setOption('_admin_route', TRUE); - - return $route; - } - } - - /** - * Gets the add-form route. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function getAddFormRoute(EntityTypeInterface $entity_type) { - if ($entity_type->hasLinkTemplate('add-form')) { - $entity_type_id = $entity_type->id(); - $route = new Route($entity_type->getLinkTemplate('add-form')); - // Use the add form handler, if available, otherwise default. - $operation = 'default'; - if ($entity_type->getFormClass('add')) { - $operation = 'add'; - } - $route - ->setDefaults([ - '_entity_form' => "{$entity_type_id}.{$operation}", - '_title' => "Add {$entity_type->getLabel()}", - ]) - ->setRequirement('_entity_create_access', $entity_type_id) - ->setOption('parameters', [ - $entity_type_id => ['type' => 'entity:' . $entity_type_id], - ]) - ->setOption('_admin_route', TRUE); - - return $route; - } - } - -} diff --git a/src/FedoraResourceTypeInterface.php b/src/FedoraResourceTypeInterface.php deleted file mode 100644 index c5e61d00..00000000 --- a/src/FedoraResourceTypeInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -t('Fedora resource type'); - $header['id'] = $this->t('Machine name'); - return $header + parent::buildHeader(); - } - - /** - * {@inheritdoc} - */ - public function buildRow(EntityInterface $entity) { - $row['label'] = $entity->label(); - $row['id'] = $entity->id(); - // You probably want a few more properties here... - return $row + parent::buildRow($entity); - } - -} diff --git a/src/FedoraResourceViewBuilder.php b/src/FedoraResourceViewBuilder.php deleted file mode 100644 index fd540bdd..00000000 --- a/src/FedoraResourceViewBuilder.php +++ /dev/null @@ -1,18 +0,0 @@ -entityFieldManager = $entity_field_manager; - $this->entityTypeManager = $entity_type_manager; - $this->moduleHandler = $module_handler; - $this->entityType = $entity_type; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $container->get('entity_field.manager'), - $container->get('entity_type.manager'), - $container->get('module_handler'), - $entity_type - ); - } - - /** - * {@inheritdoc} - */ - public function getEntityType() { - return $this->entityType; - } - - /** - * {@inheritdoc} - */ - public function getEntityTypeLabels() { - $lowercase_label = $this->entityType->getLowercaseLabel(); - return [ - 'singular' => $lowercase_label, - 'plural' => t('@entity_type entities', ['@entity_type' => $lowercase_label]), - ]; - } - - /** - * {@inheritdoc} - */ - public function getEntityLabel(EntityInterface $entity) { - return $entity->label(); - } - - /** - * {@inheritdoc} - */ - public function getTableFields($bundles) { - $definitions = $this->entityFieldManager->getBaseFieldDefinitions($this->entityType->id()); - $label_key = $this->entityType->getKey('label'); - $label_field_label = t('Label'); - if ($label_key && isset($definitions[$label_key])) { - $label_field_label = $definitions[$label_key]->getLabel(); - } - $bundle_key = $this->entityType->getKey('bundle'); - $bundle_field_label = t('Type'); - if ($bundle_key && isset($definitions[$bundle_key])) { - $bundle_field_label = $definitions[$bundle_key]->getLabel(); - } - - $fields = []; - $fields['label'] = [ - 'type' => 'label', - 'label' => $label_field_label, - 'weight' => 1, - ]; - if (count($bundles) > 1) { - $fields[$bundle_key] = [ - 'type' => 'field', - 'label' => $bundle_field_label, - 'weight' => 2, - 'display_options' => [ - 'type' => 'entity_reference_label', - 'settings' => ['link' => FALSE], - ], - ]; - } - - return $fields; - } - - /** - * {@inheritdoc} - */ - public function entityForm(array $entity_form, FormStateInterface $form_state) { - /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - $entity = $entity_form['#entity']; - $form_display = $this->getFormDisplay($entity, $entity_form['#form_mode']); - $form_display->buildForm($entity, $entity_form, $form_state); - $entity_form['#ief_element_submit'][] = [get_class($this), 'submitCleanFormState']; - // Allow other modules to alter the form. - $this->moduleHandler->alter('inline_entity_form_entity_form', $entity_form, $form_state); - - return $entity_form; - } - - /** - * {@inheritdoc} - */ - public function entityFormValidate(array &$entity_form, FormStateInterface $form_state) { - // Perform entity validation only if the inline form was submitted, - // skipping other requests such as file uploads. - $triggering_element = $form_state->getTriggeringElement(); - if (!empty($triggering_element['#ief_submit_trigger'])) { - /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - $entity = $entity_form['#entity']; - $this->buildEntity($entity_form, $entity, $form_state); - $form_display = $this->getFormDisplay($entity, $entity_form['#form_mode']); - $form_display->validateFormValues($entity, $entity_form, $form_state); - $entity->setValidationRequired(FALSE); - - foreach ($form_state->getErrors() as $name => $message) { - // $name may be unknown in $form_state and - // $form_state->setErrorByName($name, $message) - // may suppress the error message. - $form_state->setError($triggering_element, $message); - } - } - } - - /** - * {@inheritdoc} - */ - public function entityFormSubmit(array &$entity_form, FormStateInterface $form_state) { - $form_state->cleanValues(); - /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - $entity = $entity_form['#entity']; - $this->buildEntity($entity_form, $entity, $form_state); - } - - /** - * {@inheritdoc} - */ - public function save(EntityInterface $entity) { - $entity->save(); - } - - /** - * {@inheritdoc} - */ - public function delete($ids, $context) { - $storage_handler = $this->entityTypeManager->getStorage($this->entityType->id()); - $entities = $storage_handler->loadMultiple($ids); - $storage_handler->delete($entities); - } - - /** - * Builds an updated entity object based upon the submitted form values. - * - * @param array $entity_form - * The entity form. - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * The entity. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - */ - protected function buildEntity(array $entity_form, ContentEntityInterface $entity, FormStateInterface $form_state) { - $form_display = $this->getFormDisplay($entity, $entity_form['#form_mode']); - $form_display->extractFormValues($entity, $entity_form, $form_state); - // Invoke all specified builders for copying form values to entity fields. - if (isset($entity_form['#entity_builders'])) { - foreach ($entity_form['#entity_builders'] as $function) { - call_user_func_array($function, [ - $entity->getEntityTypeId(), - $entity, - &$entity_form, - &$form_state, - ]); - } - } - } - - /** - * Cleans up the form state for a submitted entity form. - * - * After field_attach_submit() has run and the form has been closed, the form - * state still contains field data in $form_state->get('field'). Unless that - * data is removed, the next form with the same #parents (reopened add form, - * for example) will contain data (i.e. uploaded files) from the previous - * form. - * - * @param array $entity_form - * The entity form. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The form state of the parent form. - */ - // @codingStandardsIgnoreLine - public static function submitCleanFormState(&$entity_form, FormStateInterface $form_state) { - $info = \Drupal::entityTypeManager()->getDefinition($entity_form['#entity_type']); - if (!$info->get('field_ui_base_route')) { - // The entity type is not fieldable, nothing to cleanup. - return; - } - - $bundle = $entity_form['#entity']->bundle(); - $instances = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_form['#entity_type'], $bundle); - foreach ($instances as $instance) { - $field_name = $instance->getName(); - if (!empty($entity_form[$field_name]['#parents'])) { - $parents = $entity_form[$field_name]['#parents']; - array_pop($parents); - if (!empty($parents)) { - $field_state = []; - WidgetBase::setWidgetState($parents, $field_name, $form_state, $field_state); - } - } - } - } - - /** - * Gets the form display for the given entity. - * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * The entity. - * @param string $form_mode - * The form mode. - * - * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface - * The form display. - */ - protected function getFormDisplay(ContentEntityInterface $entity, $form_mode) { - return EntityFormDisplay::collectRenderDisplay($entity, $form_mode); - } - -} diff --git a/src/Form/FedoraResourceForm.php b/src/Form/FedoraResourceForm.php deleted file mode 100644 index db881f72..00000000 --- a/src/Form/FedoraResourceForm.php +++ /dev/null @@ -1,48 +0,0 @@ -entity; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function save(array $form, FormStateInterface $form_state) { - $entity = $this->entity; - $status = parent::save($form, $form_state); - - switch ($status) { - case SAVED_NEW: - drupal_set_message($this->t('Created the %label Fedora resource.', [ - '%label' => $entity->label(), - ])); - break; - - default: - drupal_set_message($this->t('Saved the %label Fedora resource.', [ - '%label' => $entity->label(), - ])); - } - $form_state->setRedirect('entity.fedora_resource.canonical', ['fedora_resource' => $entity->id()]); - } - -} diff --git a/src/Form/FedoraResourceSettingsForm.php b/src/Form/FedoraResourceSettingsForm.php deleted file mode 100644 index 70b075cc..00000000 --- a/src/Form/FedoraResourceSettingsForm.php +++ /dev/null @@ -1,55 +0,0 @@ -t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return new Url('entity.fedora_resource_type.collection'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - - drupal_set_message( - $this->t('content @type: deleted @label.', - [ - '@type' => $this->entity->bundle(), - '@label' => $this->entity->label(), - ] - ) - ); - - $form_state->setRedirectUrl($this->getCancelUrl()); - } - -} diff --git a/src/Form/FedoraResourceTypeForm.php b/src/Form/FedoraResourceTypeForm.php deleted file mode 100644 index ac1a19ef..00000000 --- a/src/Form/FedoraResourceTypeForm.php +++ /dev/null @@ -1,67 +0,0 @@ -entity; - $form['label'] = [ - '#type' => 'textfield', - '#title' => $this->t('Label'), - '#maxlength' => 255, - '#default_value' => $fedora_resource_type->label(), - '#description' => $this->t("Label for the Fedora resource type."), - '#required' => TRUE, - ]; - - $form['id'] = [ - '#type' => 'machine_name', - '#default_value' => $fedora_resource_type->id(), - '#machine_name' => [ - 'exists' => '\Drupal\islandora\Entity\FedoraResourceType::load', - ], - '#disabled' => !$fedora_resource_type->isNew(), - ]; - - /* You will need additional form elements for your custom properties. */ - - return $form; - } - - /** - * {@inheritdoc} - */ - public function save(array $form, FormStateInterface $form_state) { - $fedora_resource_type = $this->entity; - $status = $fedora_resource_type->save(); - - switch ($status) { - case SAVED_NEW: - drupal_set_message($this->t('Created the %label Fedora resource type.', [ - '%label' => $fedora_resource_type->label(), - ])); - break; - - default: - drupal_set_message($this->t('Saved the %label Fedora resource type.', [ - '%label' => $fedora_resource_type->label(), - ])); - } - $form_state->setRedirectUrl($fedora_resource_type->urlInfo('collection')); - } - -} diff --git a/src/Plugin/Search/FedoraEntitySearch.php b/src/Plugin/Search/FedoraEntitySearch.php deleted file mode 100644 index 3a0ace07..00000000 --- a/src/Plugin/Search/FedoraEntitySearch.php +++ /dev/null @@ -1,839 +0,0 @@ - [ - 'column' => 'c.name', - ], - ]; - - /** - * A constant for setting and checking the query string. - */ - const ADVANCED_FORM = 'advanced-form'; - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('database'), - $container->get('entity.manager'), - $container->get('module_handler'), - $container->get('config.factory')->get('search.settings'), - $container->get('language_manager'), - $container->get('renderer'), - $container->get('current_user') - ); - } - - /** - * Constructs \Drupal\islandora\Plugin\Search\FedoraResourceSearch. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Database\Connection $database - * A database connection object. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * An entity manager object. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * A module manager object. - * @param \Drupal\Core\Config\Config $search_settings - * A config object for 'search.settings'. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - * @param \Drupal\Core\Render\RendererInterface $renderer - * Renderer. - * @param \Drupal\Core\Session\AccountInterface $account - * The $account object to use for checking for access to advanced search. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, Config $search_settings, LanguageManagerInterface $language_manager, RendererInterface $renderer, AccountInterface $account = NULL) { - $this->database = $database; - $this->entityManager = $entity_manager; - $this->moduleHandler = $module_handler; - $this->searchSettings = $search_settings; - $this->languageManager = $language_manager; - $this->renderer = $renderer; - $this->account = $account; - parent::__construct($configuration, $plugin_id, $plugin_definition); - - $this->addCacheTags(['fedora_resource_list']); - } - - /** - * {@inheritdoc} - */ - public function access($operation = 'view', AccountInterface $account = NULL, $return_as_object = FALSE) { - $result = AccessResult::allowedIfHasPermission($account, 'access content'); - return $return_as_object ? $result : $result->isAllowed(); - } - - /** - * {@inheritdoc} - */ - public function isSearchExecutable() { - // Contact search is executable if we have keywords or an advanced - // parameter. - // At least, we should parse out the parameters and see if there are any - // keyword matches in that case, rather than just printing out the - // "Please enter keywords" message. - return !empty($this->keywords) || (isset($this->searchParameters['f']) && count($this->searchParameters['f'])); - } - - /** - * {@inheritdoc} - */ - public function getType() { - return $this->getPluginId(); - } - - /** - * {@inheritdoc} - */ - public function execute() { - if ($this->isSearchExecutable()) { - $results = $this->findResults(); - - if ($results) { - return $this->prepareResults($results); - } - } - - return []; - } - - /** - * Queries to find search results, and sets status messages. - * - * This method can assume that $this->isSearchExecutable() has already been - * checked and returned TRUE. - * - * @return \Drupal\Core\Database\StatementInterface|null - * Results from search query execute() method, or NULL if the search - * failed. - */ - protected function findResults() { - - $keys = $this->keywords; - - // Build matching conditions. - $query = $this->database - ->select('search_index', 'i', ['target' => 'replica']) - ->extend('Drupal\search\SearchQuery') - ->extend('Drupal\Core\Database\Query\PagerSelectExtender'); - - // Join on {contact} and {users_field_data} to get user's published status. - // This join on {contact} also serves the advanced search items - // (in $this->advanced) that are in {contact}. - $query->join('contact', 'c', 'c.id = i.sid'); - $query->join('users_field_data', 'ufd', 'ufd.uid = c.user_id'); - $query->condition('ufd.status', 1); - - $query - ->searchExpression($keys, $this->getPluginId()); - - // @todo =============== - // Handle advanced search filters in the f query string. - // \Drupal::request()->query->get('f') is an array that looks like this in - // the URL: ?f[]=first_name:Jane&f[]=gender:f - // So $parameters['f'] looks like: - // array('first_name:Jane', 'gender:f'); - // We need to parse this out into query conditions, some of which go into - // the keywords string, and some of which are separate conditions. - // - // Note: advanced form fields are added in searchFormAlter(), - // and the URL containing the "f" parameter is built in - // buildSearchUrlQuery(). - $parameters = $this->getParameters(); - if (!empty($parameters['f']) && is_array($parameters['f'])) { - // @todo This loop should probably be moved to a helper function. - $filters = []; - // Match any query value that is an expected option and a value - // separated by ':' like 'first_name:Jane'. - $pattern = '/^(' . implode('|', array_keys($this->advanced)) . '):([^ ]*)/i'; - foreach ($parameters['f'] as $item) { - if (preg_match($pattern, $item, $m)) { - // Use the matched value as the array key to eliminate duplicates. - $filters[$m[1]][$m[2]] = $m[2]; - } - } - - // Now turn these into query conditions. This assumes that everything in - // $filters is a known type of advanced search as defined in - // $this->advanced. - foreach ($filters as $option => $matched) { - $info = $this->advanced[$option]; - // Insert additional conditions. By default, all use the OR operator. - $operator = empty($info['operator']) ? 'OR' : $info['operator']; - $where = new Condition($operator); - foreach ($matched as $value) { - $where->condition($info['column'], $value); - } - $query->condition($where); - if (!empty($info['join'])) { - $query->join($info['join']['table'], $info['join']['alias'], $info['join']['condition']); - } - } - } - // =============== - // Add the ranking expressions. - $this->addFedoraResourceRankings($query); - - // Run the query. - $find = $query - // Add the language code of the indexed item to the result of the query, - // since the entity will be rendered using the respective language. - ->fields('i', ['langcode']) - // And since SearchQuery makes these into GROUP BY queries, if we add - // a field, for PostgreSQL we also need to make it an aggregate or a - // GROUP BY. In this case, we want GROUP BY. - ->groupBy('i.langcode') - ->limit(10) - ->execute(); - - // Check query status and set messages if needed. - $status = $query->getStatus(); - - if ($status & SearchQuery::EXPRESSIONS_IGNORED) { - drupal_set_message($this->t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', ['@count' => $this->searchSettings->get('and_or_limit')]), 'warning'); - } - - if ($status & SearchQuery::LOWER_CASE_OR) { - drupal_set_message($this->t('Search for either of the two terms with uppercase OR. For example, cats OR dogs.'), 'warning'); - } - - if ($status & SearchQuery::NO_POSITIVE_KEYWORDS) { - drupal_set_message($this->formatPlural($this->searchSettings->get('index.minimum_word_size'), 'You must include at least one keyword to match in the content, and punctuation is ignored.', 'You must include at least one keyword to match in the content. Keywords must be at least @count characters, and punctuation is ignored.'), 'warning'); - } - - return $find; - } - - /** - * Prepares search results for rendering. - * - * @param \Drupal\Core\Database\StatementInterface $found - * Results found from a successful search query execute() method. - * - * @return array - * Array of search result item render arrays (empty array if no results). - */ - protected function prepareResults(StatementInterface $found) { - $results = []; - - // 'fedora_resource' comes from the entity type id declared - // in the annotation for \Drupal\islandora\Entity\FedoraResource. - // Replace this with your entity's type id. - $entity_storage = $this->entityManager->getStorage('fedora_resource'); - $entity_render = $this->entityManager->getViewBuilder('fedora_resource'); - $keys = $this->keywords; - - foreach ($found as $item) { - // Render the contact. - /** @var \Drupal\content_entity_example\ContactInterface $entity */ - $entity = $entity_storage->load($item->sid)->getTranslation($item->langcode); - $build = $entity_render->view($entity, 'search_result', $item->langcode); - - unset($build['#theme']); - // Uncomment to use removeFromSnippet() for excluding data from snippet. - /* $build['#pre_render'][] = array($this, 'removeFromSnippet'); */ - - // Build the snippet. - $rendered = $this->renderer->renderPlain($build); - $this->addCacheableDependency(CacheableMetadata::createFromRenderArray($build)); - // Allow other modules to add to snippet. - $rendered .= ' ' . $this->moduleHandler->invokeAll('fedora_resource_update_index', [$entity]); - - $extra = $this->moduleHandler->invokeAll('fedora_resource_search_result', [$entity]); - - $language = $this->languageManager->getLanguage($item->langcode); - - $result = [ - 'link' => $entity->url( - 'canonical', - [ - 'absolute' => TRUE, - 'language' => $language, - ] - ), - 'type' => 'Fedora Resource', - 'title' => $entity->label(), - 'contact' => $entity, - 'extra' => $extra, - 'score' => $item->calculated_score, - 'snippet' => search_excerpt($keys, $rendered, $item->langcode), - 'langcode' => $entity->language()->getId(), - ]; - - $this->addCacheableDependency($entity); - - // We have to separately add the contact owner's cache tags because search - // module doesn't use the rendering system, it does its own rendering - // without taking cacheability metadata into account. So we have to do it - // explicitly here. - $this->addCacheableDependency($entity->getOwner()); - - // @codingStandardsIgnoreStart - // Uncomment this to display owner name and last changed time. - // $username = array( - // '#theme' => 'username', - // '#account' => $entity->getOwner(), - // ); - // $result += array( - // 'user' => $this->renderer->renderPlain($username), - // 'date' => $entity->getChangedTime(), - // ); - // @codingStandardsIgnoreEnd - $results[] = $result; - - } - return $results; - } - - /** - * Removes results data from the build array. - * - * This information is being removed from the rendered entity that is used to - * build the search result snippet. - * - * @param array $build - * The build array. - * - * @return array - * The modified build array. - */ - public function removeFromSnippet(array $build) { - // Code to remove arbitrary data from $build goes here. - // Examples: - // - unset($build['created']); - // - unset($build['uid']);. - return $build; - } - - /** - * Adds the configured rankings to the search query. - * - * @param \Drupal\Core\Database\Query\SelectExtender $query - * A query object that has been extended with the Search DB Extender. - */ - protected function addFedoraResourceRankings(SelectExtender $query) { - if ($ranking = $this->getRankings()) { - $tables = &$query->getTables(); - foreach ($ranking as $rank => $values) { - if (isset($this->configuration['rankings'][$rank]) && !empty($this->configuration['rankings'][$rank])) { - $entity_rank = $this->configuration['rankings'][$rank]; - // If the table defined in the ranking isn't already joined, add it. - if (isset($values['join']) && !isset($tables[$values['join']['alias']])) { - $query->addJoin($values['join']['type'], $values['join']['table'], $values['join']['alias'], $values['join']['on']); - } - $arguments = isset($values['arguments']) ? $values['arguments'] : []; - $query->addScore($values['score'], $arguments, $entity_rank); - } - } - } - } - - /** - * {@inheritdoc} - */ - public function updateIndex() { - // Interpret the cron limit setting as the maximum number of entities to - // index per cron run. - $limit = (int) $this->searchSettings->get('index.cron_limit'); - - $result = $this->database->queryRange("SELECT c.id, MAX(sd.reindex) FROM {fedora_resource} c LEFT JOIN {search_dataset} sd ON sd.sid = c.id AND sd.type = :type WHERE sd.sid IS NULL OR sd.reindex <> 0 GROUP BY c.id ORDER BY MAX(sd.reindex) is null DESC, MAX(sd.reindex) ASC, c.id ASC", 0, $limit, [':type' => $this->getPluginId()], ['target' => 'replica']); - - $rids = $result->fetchCol(); - if (!$rids) { - return; - } - - // 'fedora_resource' comes from the entity type id declared - // in the annotation for \Drupal\islandora\Entity\FedoraResource. - // Replace this with your entity's type id. - $entity_storage = $this->entityManager->getStorage('fedora_resource'); - - foreach ($entity_storage->loadMultiple($rids) as $entity) { - $this->indexFedoraResource($entity); - } - } - - /** - * Indexes a single contact. - * - * @param \Drupal\islandora\FedoraResourceInterface $entity - * The contact to index. - */ - protected function indexFedoraResource(FedoraResourceInterface $entity) { - $languages = $entity->getTranslationLanguages(); - // 'content_entity_example_contact' comes from the entity type id declared - // in the annotation for \Drupal\content_entity_example\Entity\Contact. - // Replace this with your entity's type id. - $entity_render = $this->entityManager->getViewBuilder('fedora_resource'); - - foreach ($languages as $language) { - $entity = $entity->getTranslation($language->getId()); - // Render the contact. - $build = $entity_render->view($entity, 'search_index', $language->getId()); - - unset($build['#theme']); - - // Add the title to text so it is searchable. - $build['search_title'] = [ - '#prefix' => '', - '#plain_text' => $entity->label(), - '#suffix' => '', - '#weight' => -1000, - ]; - $text = $this->renderer->renderPlain($build); - - // Fetch extra data normally not visible. - $extra = $this->moduleHandler->invokeAll('fedora_resource_update_index', [$entity]); - foreach ($extra as $t) { - $text .= $t; - } - - // Update index, using search index "type" equal to the plugin ID. - search_index($this->getPluginId(), $entity->id(), $language->getId(), $text); - } - } - - /** - * {@inheritdoc} - */ - public function indexClear() { - // All ContactSearch pages share a common search index "type" equal to - // the plugin ID. - search_index_clear($this->getPluginId()); - } - - /** - * {@inheritdoc} - */ - public function markForReindex() { - // All ContactSearch pages share a common search index "type" equal to - // the plugin ID. - search_mark_for_reindex($this->getPluginId()); - } - - /** - * {@inheritdoc} - */ - public function indexStatus() { - - $total = $this->database->query('SELECT COUNT(*) FROM {fedora_resource}')->fetchField(); - $remaining = $this->database->query("SELECT COUNT(DISTINCT c.id) FROM {contact} c LEFT JOIN {search_dataset} sd ON sd.sid = c.id AND sd.type = :type WHERE sd.sid IS NULL OR sd.reindex <> 0", [':type' => $this->getPluginId()])->fetchField(); - - return ['remaining' => $remaining, 'total' => $total]; - } - - /** - * {@inheritdoc} - */ - public function searchFormAlter(array &$form, FormStateInterface $form_state) { - $parameters = $this->getParameters(); - $keys = $this->getKeywords(); - $used_advanced = !empty($parameters[self::ADVANCED_FORM]); - if ($used_advanced) { - $f = isset($parameters['f']) ? (array) $parameters['f'] : []; - $defaults = $this->parseAdvancedDefaults($f, $keys); - } - else { - $defaults = ['keys' => $keys]; - } - - $form['basic']['keys']['#default_value'] = $defaults['keys']; - - // Add advanced search keyword-related boxes. - $form['advanced'] = [ - '#type' => 'details', - '#title' => t('Advanced search'), - '#attributes' => ['class' => ['search-advanced']], - '#access' => $this->account && $this->account->hasPermission('use advanced search'), - '#open' => $used_advanced, - ]; - $form['advanced']['keywords-fieldset'] = [ - '#type' => 'fieldset', - '#title' => t('Keywords'), - ]; - - $form['advanced']['keywords-fieldset']['keywords']['or'] = [ - '#type' => 'textfield', - '#title' => t('Containing any of the words'), - '#size' => 30, - '#maxlength' => 255, - '#default_value' => isset($defaults['or']) ? $defaults['or'] : '', - ]; - - $form['advanced']['keywords-fieldset']['keywords']['phrase'] = [ - '#type' => 'textfield', - '#title' => t('Containing the phrase'), - '#size' => 30, - '#maxlength' => 255, - '#default_value' => isset($defaults['phrase']) ? $defaults['phrase'] : '', - ]; - - $form['advanced']['keywords-fieldset']['keywords']['negative'] = [ - '#type' => 'textfield', - '#title' => t('Containing none of the words'), - '#size' => 30, - '#maxlength' => 255, - '#default_value' => isset($defaults['negative']) ? $defaults['negative'] : '', - ]; - - $form['advanced']['misc-fieldset'] = [ - '#type' => 'fieldset', - ]; - - // \Drupal\search\SearchQuery requires that there be valid keywords - // submitted in the standard fields. - $form['advanced']['misc-fieldset']['note'] = [ - '#markup' => t('You must still enter keyword(s) above when using these fields.'), - '#weight' => -10, - ]; - - $form['advanced']['misc-fieldset']['name'] = [ - '#type' => 'textfield', - '#title' => t('Name'), - '#description' => t('Search %field field for exact matches.', ['%field' => 'Name']), - '#default_value' => isset($defaults['name']) ? $defaults['name'] : [], - ]; - - $form['advanced']['submit'] = [ - '#type' => 'submit', - '#value' => t('Advanced search'), - '#prefix' => '', - '#suffix' => '', - '#weight' => 100, - ]; - } - - /** - * {@inheritdoc} - */ - public function buildSearchUrlQuery(FormStateInterface $form_state) { - // Read keyword and advanced search information from the form values, - // and put these into the GET parameters. - $keys = trim($form_state->getValue('keys')); - $advanced = FALSE; - - // Collect extra filters. - $filters = []; - - // Advanced form, custom_content_entity_example_contact fields. - if ($form_state->hasValue('name') && !empty(($value = trim($form_state->getValue('name'))))) { - $filters[] = 'name:' . $value; - $advanced = TRUE; - } - - // Advanced form, keywords fields. - if ($form_state->getValue('or') != '') { - if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state->getValue('or'), $matches)) { - $keys .= ' ' . implode(' OR ', $matches[1]); - $advanced = TRUE; - } - } - if ($form_state->getValue('negative') != '') { - if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state->getValue('negative'), $matches)) { - $keys .= ' -' . implode(' -', $matches[1]); - $advanced = TRUE; - } - } - if ($form_state->getValue('phrase') != '') { - $keys .= ' "' . str_replace('"', ' ', $form_state->getValue('phrase')) . '"'; - $advanced = TRUE; - } - $keys = trim($keys); - - // Put the keywords and advanced parameters into GET parameters. Make sure - // to put keywords into the query even if it is empty, because the page - // controller uses that to decide it's time to check for search results. - $query = ['keys' => $keys]; - if ($filters) { - $query['f'] = $filters; - } - // Record that the person used the advanced search form, if they did. - if ($advanced) { - $query[self::ADVANCED_FORM] = '1'; - } - - return $query; - } - - /** - * Parses the advanced search form default values. - * - * @param array $f - * The 'f' query parameter set up in self::buildUrlSearchQuery(), which - * contains the advanced query values. - * @param string $keys - * The search keywords string, which contains some information from the - * advanced search form. - * - * @return array - * Array of default form values for the advanced search form, including - * a modified 'keys' element for the bare search keywords. - */ - protected function parseAdvancedDefaults(array $f, $keys) { - $defaults = []; - - // Split out the advanced search parameters. - foreach ($f as $advanced) { - list($key, $value) = explode(':', $advanced, 2); - if (!isset($defaults[$key])) { - $defaults[$key] = []; - } - $defaults[$key][] = $value; - } - - // Split out the negative, phrase, and OR parts of keywords. - // For phrases, the form only supports one phrase. - $matches = []; - $keys = ' ' . $keys . ' '; - if (preg_match('/ "([^"]+)" /', $keys, $matches)) { - $keys = str_replace($matches[0], ' ', $keys); - $defaults['phrase'] = $matches[1]; - } - - // Negative keywords: pull all of them out. - if (preg_match_all('/ -([^ ]+)/', $keys, $matches)) { - $keys = str_replace($matches[0], ' ', $keys); - $defaults['negative'] = implode(' ', $matches[1]); - } - - // OR keywords: pull up to one set of them out of the query. - if (preg_match('/ [^ ]+( OR [^ ]+)+ /', $keys, $matches)) { - $keys = str_replace($matches[0], ' ', $keys); - $words = explode(' OR ', trim($matches[0])); - $defaults['or'] = implode(' ', $words); - } - - // Put remaining keywords string back into keywords. - $defaults['keys'] = trim($keys); - - return $defaults; - } - - /** - * Gathers ranking definitions from hook_ranking(). - * - * @return array - * An array of ranking definitions. - */ - protected function getRankings() { - if (!$this->rankings) { - $this->rankings = $this->moduleHandler->invokeAll('ranking'); - } - return $this->rankings; - } - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - $configuration = [ - 'rankings' => [], - ]; - return $configuration; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - // Output form for defining rank factor weights. - $form['content_ranking'] = [ - '#type' => 'details', - '#title' => t('Content ranking'), - '#open' => TRUE, - ]; - $form['content_ranking']['info'] = [ - '#markup' => '' . $this->t('Influence is a numeric multiplier used in ordering search results. A higher number means the corresponding factor has more influence on search results; zero means the factor is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '', - ]; - // Prepare table. - $header = [$this->t('Factor'), $this->t('Influence')]; - $form['content_ranking']['rankings'] = [ - '#type' => 'table', - '#header' => $header, - ]; - - // Note: reversed to reflect that higher number = higher ranking. - $range = range(0, 10); - $options = array_combine($range, $range); - foreach ($this->getRankings() as $var => $values) { - $form['content_ranking']['rankings'][$var]['name'] = [ - '#markup' => $values['title'], - ]; - $form['content_ranking']['rankings'][$var]['value'] = [ - '#type' => 'select', - '#options' => $options, - '#attributes' => ['aria-label' => $this->t("Influence of '@title'", ['@title' => $values['title']])], - '#default_value' => isset($this->configuration['rankings'][$var]) ? $this->configuration['rankings'][$var] : 0, - ]; - } - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - foreach ($this->getRankings() as $var => $values) { - if (!$form_state->isValueEmpty(['rankings', $var, 'value'])) { - $this->configuration['rankings'][$var] - = $form_state->getValue(['rankings', $var, 'value']); - } - else { - unset($this->configuration['rankings'][$var]); - } - } - } - -} diff --git a/src/Plugin/views/wizard/FedoraResource.php b/src/Plugin/views/wizard/FedoraResource.php deleted file mode 100644 index 50c12f1c..00000000 --- a/src/Plugin/views/wizard/FedoraResource.php +++ /dev/null @@ -1,130 +0,0 @@ - $this->t('Name'), - ]; - } - - /** - * {@inheritdoc} - */ - protected function defaultDisplayOptions() { - $display_options = parent::defaultDisplayOptions(); - - // Add permission-based access control. - $display_options['access']['type'] = 'perm'; - $display_options['access']['options']['perm'] = 'access content'; - - // Remove the default fields, since we are customizing them here. - unset($display_options['fields']); - - // Add the title field, so that the display has content if the user switches - // to a row style that uses fields. - /* Field: Content: Title */ - $display_options['fields']['name']['id'] = 'name'; - $display_options['fields']['name']['table'] = 'fedora_resource_field_data'; - $display_options['fields']['name']['field'] = 'name'; - $display_options['fields']['name']['entity_type'] = 'fedora_resource'; - $display_options['fields']['name']['entity_field'] = 'name'; - $display_options['fields']['name']['label'] = ''; - $display_options['fields']['name']['alter']['alter_text'] = 0; - $display_options['fields']['name']['alter']['make_link'] = 0; - $display_options['fields']['name']['alter']['absolute'] = 0; - $display_options['fields']['name']['alter']['trim'] = 0; - $display_options['fields']['name']['alter']['word_boundary'] = 0; - $display_options['fields']['name']['alter']['ellipsis'] = 0; - $display_options['fields']['name']['alter']['strip_tags'] = 0; - $display_options['fields']['name']['alter']['html'] = 0; - $display_options['fields']['name']['hide_empty'] = 0; - $display_options['fields']['name']['empty_zero'] = 0; - $display_options['fields']['name']['settings']['link_to_entity'] = 1; - $display_options['fields']['name']['plugin_id'] = 'field'; - - return $display_options; - } - - /** - * {@inheritdoc} - */ - protected function pageDisplayOptions(array $form, FormStateInterface $form_state) { - $display_options = parent::pageDisplayOptions($form, $form_state); - $row_plugin = $form_state->getValue(['page', 'style', 'row_plugin']); - $row_options = $form_state->getValue(['page', 'style', 'row_options'], []); - $this->display_options_row($display_options, $row_plugin, $row_options); - return $display_options; - } - - /** - * {@inheritdoc} - */ - protected function blockDisplayOptions(array $form, FormStateInterface $form_state) { - $display_options = parent::blockDisplayOptions($form, $form_state); - $row_plugin = $form_state->getValue(['block', 'style', 'row_plugin']); - $row_options = $form_state->getValue(['block', 'style', 'row_options'], []); - $this->displayOptionsRow($display_options, $row_plugin, $row_options); - return $display_options; - } - - /** - * Set the row style and row style plugins to the display_options. - */ - protected function displayOptionsRow(&$display_options, $row_plugin, $row_options) { - switch ($row_plugin) { - case 'full_posts': - $display_options['row']['type'] = 'entity:fedora_resource'; - $display_options['row']['options']['view_mode'] = 'full'; - break; - - case 'teasers': - $display_options['row']['type'] = 'entity:fedora_resource'; - $display_options['row']['options']['view_mode'] = 'teaser'; - break; - - case 'titles_linked': - case 'titles': - $display_options['row']['type'] = 'fields'; - $display_options['fields']['title']['id'] = 'title'; - $display_options['fields']['title']['table'] = 'fedora_resource_field_data'; - $display_options['fields']['title']['field'] = 'title'; - $display_options['fields']['title']['settings']['link_to_entity'] = $row_plugin === 'titles_linked'; - $display_options['fields']['title']['plugin_id'] = 'field'; - break; - } - } - -} diff --git a/src/Tests/Web/JsonldContextGeneratorWebTest.php b/src/Tests/Web/JsonldContextGeneratorWebTest.php index dbd000bd..6e921e45 100644 --- a/src/Tests/Web/JsonldContextGeneratorWebTest.php +++ b/src/Tests/Web/JsonldContextGeneratorWebTest.php @@ -3,7 +3,7 @@ namespace Drupal\islandora\Tests\Web; use Drupal\Core\Url; -use Drupal\islandora\Entity\FedoraResourceType; +use Drupal\node\Entity\NodeType; use Drupal\rdf\Entity\RdfMapping; /** @@ -33,33 +33,31 @@ class JsonldContextGeneratorWebTest extends IslandoraWebTestBase { public function setUp() { parent::setUp(); - // Create a bundle to test. - $rdf_source = FedoraResourceType::create([ - 'id' => 'rdf_source', - 'label' => 'RdfSource', + $test_type = NodeType::create([ + 'type' => 'test_type', + 'label' => 'Test Type', ]); - $rdf_source->save(); + $test_type->save(); // Give it a basic rdf mapping. - $rdf_source_mapping = RdfMapping::create([ - 'id' => 'fedora_resourcce.rdf_source', - 'targetEntityType' => 'fedora_resource', - 'bundle' => 'rdf_source', + $mapping = RdfMapping::create([ + 'id' => 'node.test_type', + 'targetEntityType' => 'node', + 'bundle' => 'test_type', 'types' => ['schema:Thing'], 'fieldMappings' => [ - 'name' => [ + 'title' => [ 'properties' => ['dc11:title'], ], ], ]); - $rdf_source_mapping->save(); + $mapping->save(); $this->user = $this->drupalCreateUser([ 'administer site configuration', - 'view published fedora resource entities', - 'access content', - ] - ); + 'administer nodes', + ]); + // Login. $this->drupalLogin($this->user); } @@ -68,7 +66,7 @@ class JsonldContextGeneratorWebTest extends IslandoraWebTestBase { * Tests that the Context Response Page can be reached. */ public function testJsonldcontextPageExists() { - $url = Url::fromRoute('entity.fedora_resource_type.jsonldcontext', ['bundle' => 'rdf_source']); + $url = Url::fromRoute('islandora.jsonldcontext', ['entity_type' => 'node', 'bundle' => 'test_type']); $this->drupalGet($url); $this->assertResponse(200); } @@ -77,7 +75,7 @@ class JsonldContextGeneratorWebTest extends IslandoraWebTestBase { * Tests that the response is in fact application/ld+json. */ public function testJsonldcontextContentypeheaderResponseIsValid() { - $url = Url::fromRoute('entity.fedora_resource_type.jsonldcontext', ['bundle' => 'rdf_source']); + $url = Url::fromRoute('islandora.jsonldcontext', ['entity_type' => 'node', 'bundle' => 'test_type']); $this->drupalGet($url); $this->assertEqual($this->drupalGetHeader('Content-Type'), 'application/ld+json', 'Correct JSON-LD mime type was returned'); } @@ -86,7 +84,7 @@ class JsonldContextGeneratorWebTest extends IslandoraWebTestBase { * Tests that the Context received has the basic structural needs. */ public function testJsonldcontextResponseIsValid() { - $url = Url::fromRoute('entity.fedora_resource_type.jsonldcontext', ['bundle' => 'rdf_source']); + $url = Url::fromRoute('islandora.jsonldcontext', ['entity_type' => 'node', 'bundle' => 'test_type']); $this->drupalGet($url); $jsonldarray = json_decode($this->getRawContent(), TRUE); // Check if the only key is "@context". diff --git a/templates/fedora-resource-content-add-list.html.twig b/templates/fedora-resource-content-add-list.html.twig deleted file mode 100644 index edb8bddd..00000000 --- a/templates/fedora-resource-content-add-list.html.twig +++ /dev/null @@ -1,23 +0,0 @@ -{# -/** - * @file - * Default theme implementation to present a list of custom content entity types/bundles. - * - * Available variables: - * - types: A collection of all the available custom entity types/bundles. - * Each type/bundle contains the following: - * - link: A link to add a content entity of this type. - * - description: A description of this content entity types/bundle. - * - * @see template_preprocess_fedora_resource_content_add_list() - * - * @ingroup themeable - */ -#} -{% spaceless %} -
- {% for type in types %} -
{{ type.link }}
- {% endfor %} -
-{% endspaceless %} diff --git a/templates/fedora_resource.html.twig b/templates/fedora_resource.html.twig deleted file mode 100644 index bfdd80d1..00000000 --- a/templates/fedora_resource.html.twig +++ /dev/null @@ -1,22 +0,0 @@ -{# -/** - * @file fedora_resource.html.twig - * Default theme implementation to present Fedora resource data. - * - * This template is used when viewing Fedora resource pages. - * - * - * Available variables: - * - content: A list of content items. Use 'content' to print all content, or - * - attributes: HTML attributes for the container element. - * - * @see template_preprocess_fedora_resource() - * - * @ingroup themeable - */ -#} - - {% if content %} - {{- content -}} - {% endif %} - diff --git a/tests/src/Kernel/DeleteFedoraResourceWithParentsTest.php b/tests/src/Kernel/DeleteFedoraResourceWithParentsTest.php deleted file mode 100644 index ea496c29..00000000 --- a/tests/src/Kernel/DeleteFedoraResourceWithParentsTest.php +++ /dev/null @@ -1,92 +0,0 @@ -assertTrue($this->checkPermissions($permissions), 'Permissions are invalid'); - - $this->user = $this->createUser($permissions); - - // Create a test entity. - $this->parentEntity = FedoraResource::create([ - "type" => "rdf_source", - "uid" => $this->user->get('uid'), - "name" => "Test Parent", - "langcode" => "und", - "status" => 1, - ]); - $this->parentEntity->save(); - - $this->childEntity = FedoraResource::create([ - "type" => "rdf_source", - "uid" => $this->user->get('uid'), - "name" => "Test Child", - "langcode" => "und", - "fedora_has_parent" => $this->parentEntity, - "status" => 1, - ]); - $this->childEntity->save(); - } - - /** - * Tests cleaning up child to parent references when parent is deleted. - * - * @covers \Drupal\islandora\Entity\FedoraResource::postDelete - */ - public function testCleanUpParents() { - $child_id = $this->childEntity->id(); - // Load the child entity. - $new_child = FedoraResource::load($child_id); - // Verify it has a parent. - $this->assertFalse($new_child->get('fedora_has_parent')->isEmpty(), "Should have a parent."); - // Delete the parent entity. - $this->parentEntity->delete(); - // Verify we don't have a parent anymore. - $this->assertTrue($new_child->get('fedora_has_parent')->isEmpty(), "Should not have a parent."); - - } - -} diff --git a/tests/src/Kernel/EventGeneratorTestBase.php b/tests/src/Kernel/EventGeneratorTestBase.php index 228437e3..810f91f4 100644 --- a/tests/src/Kernel/EventGeneratorTestBase.php +++ b/tests/src/Kernel/EventGeneratorTestBase.php @@ -2,7 +2,8 @@ namespace Drupal\Tests\islandora\Kernel; -use Drupal\islandora\Entity\FedoraResource; +use Drupal\node\Entity\Node; +use Drupal\node\Entity\NodeType; use Drupal\simpletest\UserCreationTrait; /** @@ -22,7 +23,7 @@ abstract class EventGeneratorTestBase extends IslandoraKernelTestBase { /** * Fedora resource entity. * - * @var \Drupal\islandora\FedoraResourceInterface + * @var \Drupal\node\Entity\NodeInterface */ protected $entity; @@ -35,11 +36,17 @@ abstract class EventGeneratorTestBase extends IslandoraKernelTestBase { // Create a test user. $this->user = $this->createUser(['add fedora resource entities']); + $test_type = NodeType::create([ + 'type' => 'test_type', + 'label' => 'Test Type', + ]); + $test_type->save(); + // Create a test entity. - $this->entity = FedoraResource::create([ - "type" => "rdf_source", + $this->entity = Node::create([ + "type" => "test_type", "uid" => $this->user->get('uid'), - "name" => "Test Fixture", + "title" => "Test Fixture", "langcode" => "und", "status" => 1, ]); diff --git a/tests/src/Kernel/FedoraContentTypeCreationTrait.php b/tests/src/Kernel/FedoraContentTypeCreationTrait.php deleted file mode 100644 index dc549808..00000000 --- a/tests/src/Kernel/FedoraContentTypeCreationTrait.php +++ /dev/null @@ -1,43 +0,0 @@ - 'some_bundle'. - * - * @return \Drupal\islandora\Entity\FedoraResourceType - * Created content type. - */ - protected function createFedoraResourceContentType(array $values = []) { - // Find a non-existent random type name. - $random = new Random(); - if (!isset($values['type'])) { - do { - $id = strtolower($random->string(8)); - } while (FedoraResourceType::load($id)); - } - else { - $id = $values['type']; - } - $values += [ - 'id' => $id, - 'label' => $id, - ]; - $type = FedoraResourceType::create($values); - $type->save(); - return $type; - } - -} diff --git a/tests/src/Kernel/FedoraResourceParentTest.php b/tests/src/Kernel/FedoraResourceParentTest.php deleted file mode 100644 index 9c8da719..00000000 --- a/tests/src/Kernel/FedoraResourceParentTest.php +++ /dev/null @@ -1,134 +0,0 @@ -assertTrue($this->checkPermissions($permissions), 'Permissions are invalid'); - - $this->user = $this->createUser($permissions); - - $this->entity = FedoraResource::create([ - 'type' => 'rdf_source', - 'uid' => $this->user->get('uid'), - 'name' => 'Test Entity', - 'langcode' => 'und', - 'status' => 1, - ]); - $this->entity->save(); - - $this->parentEntity = FedoraResource::create([ - 'type' => 'rdf_source', - 'uid' => $this->user->get('uid'), - 'name' => 'Parent Entity', - 'langcode' => 'und', - 'status' => 1, - ]); - $this->parentEntity->save(); - } - - /** - * @covers \Drupal\islandora\Entity\FedoraResource::setParent - */ - public function testSetParent() { - $this->assertTrue($this->entity->get('fedora_has_parent')->isEmpty(), "Entity has an unexpected parent."); - - $this->entity->setParent($this->parentEntity); - $this->entity->save(); - - $this->assertFalse($this->entity->get('fedora_has_parent')->isEmpty(), "Entity has no parent."); - } - - /** - * @covers \Drupal\islandora\Entity\FedoraResource::removeParent - */ - public function testRemoveParent() { - $this->assertTrue($this->entity->get('fedora_has_parent')->isEmpty(), "Entity has an unexpected parent."); - - $this->entity->set('fedora_has_parent', $this->parentEntity); - $this->entity->save(); - - $this->assertFalse($this->entity->get('fedora_has_parent')->isEmpty(), "Entity has no parent."); - - $this->entity->removeParent(); - $this->entity->save(); - - $this->assertTrue($this->entity->get('fedora_has_parent')->isEmpty(), "Entity has an unexpected parent."); - } - - /** - * @covers \Drupal\islandora\Entity\FedoraResource::hasParent - */ - public function testHasParent() { - $this->assertTrue($this->entity->get('fedora_has_parent')->isEmpty(), "Entity has an unexpected parent."); - $this->assertFalse($this->entity->hasParent(), "hasParent is reporting a parent incorrectly."); - - $this->entity->set('fedora_has_parent', $this->parentEntity); - $this->entity->save(); - - $this->assertFalse($this->entity->get('fedora_has_parent')->isEmpty(), "Entity has no parent."); - $this->assertTrue($this->entity->hasParent(), "hasParent is reporting NO parent incorrectly."); - - $this->entity->set('fedora_has_parent', NULL); - $this->entity->save(); - - $this->assertTrue($this->entity->get('fedora_has_parent')->isEmpty(), "Entity still has a parent."); - $this->assertFalse($this->entity->hasParent(), "hasParent is reporting a parent incorrectly."); - } - - /** - * @covers \Drupal\islandora\Entity\FedoraResource::getParentId - */ - public function testGetParentId() { - $id = $this->parentEntity->id(); - - $this->entity->set('fedora_has_parent', $this->parentEntity); - $this->entity->save(); - - $this->assertEquals($id, $this->entity->getParentId(), "Did not get correct parent id."); - } - -} diff --git a/tests/src/Kernel/IslandoraKernelTestBase.php b/tests/src/Kernel/IslandoraKernelTestBase.php index cc4d901b..b801ec5a 100644 --- a/tests/src/Kernel/IslandoraKernelTestBase.php +++ b/tests/src/Kernel/IslandoraKernelTestBase.php @@ -49,10 +49,11 @@ abstract class IslandoraKernelTestBase extends KernelTestBase { // Bootstrap minimal Drupal environment to run the tests. $this->installSchema('system', 'sequences'); + $this->installSchema('node', 'node_access'); $this->installEntitySchema('user'); + $this->installEntitySchema('node'); $this->installConfig('filter'); $this->installSchema('islandora', 'islandora_version_count'); - $this->installEntitySchema('fedora_resource'); } } diff --git a/tests/src/Kernel/VersionCounterTest.php b/tests/src/Kernel/VersionCounterTest.php index 9255f256..225fc66d 100644 --- a/tests/src/Kernel/VersionCounterTest.php +++ b/tests/src/Kernel/VersionCounterTest.php @@ -2,14 +2,15 @@ namespace Drupal\Tests\islandora\Kernel; -use Drupal\islandora\Entity\FedoraResource; +use Drupal\node\Entity\Node; +use Drupal\node\Entity\NodeType; use Drupal\simpletest\UserCreationTrait; /** * Tests the basic behavior of a vector clock. * * @group islandora - * @coversDefaultClass \Drupal\islandora\Entity\FedoraResource + * @coversDefaultClass \Drupal\islandora\VersionCounter\VersionCounter */ class VersionCounterTest extends IslandoraKernelTestBase { @@ -18,7 +19,7 @@ class VersionCounterTest extends IslandoraKernelTestBase { /** * Fedora resource entity. * - * @var \Drupal\islandora\FedoraResourceInterface + * @var \Drupal\node\Entity\NodeInterface */ protected $entity; @@ -36,13 +37,19 @@ class VersionCounterTest extends IslandoraKernelTestBase { parent::setUp(); // Create a test user. - $this->user = $this->createUser(['add fedora resource entities', 'edit fedora resource entities']); + $this->user = $this->createUser(['administer nodes']); + + $test_type = NodeType::create([ + 'type' => 'test_type', + 'label' => 'Test Type', + ]); + $test_type->save(); // Create a test entity. - $this->entity = FedoraResource::create([ - "type" => "rdf_source", + $this->entity = Node::create([ + "type" => "test_type", "uid" => $this->user->get('uid'), - "name" => "Test Fixture", + "title" => "Test Fixture", "langcode" => "und", "status" => 1, ]); @@ -75,7 +82,7 @@ class VersionCounterTest extends IslandoraKernelTestBase { * @covers \Drupal\islandora\VersionCounter\VersionCounter::get */ public function testRecordIncrementsOnUpdate() { - $this->entity->setName("New Name"); + $this->entity->setTitle("New Title"); $this->entity->save(); $versionCounter = $this->container->get('islandora.versioncounter');