diff --git a/README.md b/README.md index 9cfff051..005eb12c 100644 --- a/README.md +++ b/README.md @@ -1 +1,25 @@ -# claw-drupal8 \ No newline at end of file +# Islandora +[![Build Status](https://travis-ci.org/Islandora-CLAW/islandora.png?branch=8.x-1.x)](https://travis-ci.org/Islandora-CLAW/islandora) +[![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md) +[![LICENSE](https://img.shields.io/badge/license-GPLv2-blue.svg?style=flat-square)](./LICENSE) + +## Introduction + +Islandora Fedora 4 Repository Module for Drupal 8.1.x + +## Maintainers + +Current maintainers: + +* [Diego Pino](https://github.com/diegopino) +* [Jared Whiklo](https://github.com/whikloj) + +## Development + +If you would like to contribute, please get involved by attending our weekly [Tech Call](https://github.com/Islandora-CLAW/CLAW/wiki). We love to hear from you! + +If you would like to contribute code to the project, you need to be covered by an Islandora Foundation [Contributor License Agreement](http://islandora.ca/sites/default/files/islandora_cla.pdf) or [Corporate Contributor Licencse Agreement](http://islandora.ca/sites/default/files/islandora_ccla.pdf). Please see the [Contributors](http://islandora.ca/resources/contributors) pages on Islandora.ca for more information. + +## License + +[GPLv2](http://www.gnu.org/licenses/gpl-2.0.txt) \ No newline at end of file diff --git a/config/install/islandora.fedora_resource_type.non_rdf_source.yml b/config/install/islandora.fedora_resource_type.non_rdf_source.yml index 245224d3..6a0cb707 100644 --- a/config/install/islandora.fedora_resource_type.non_rdf_source.yml +++ b/config/install/islandora.fedora_resource_type.non_rdf_source.yml @@ -1,4 +1,3 @@ langcode: en id: non_rdf_source -label: 'Non RDF Source' -rdf_type: fedora:Binary \ No newline at end of file +label: 'Non RDF Source' \ No newline at end of file diff --git a/config/install/islandora.fedora_resource_type.rdf_source.yml b/config/install/islandora.fedora_resource_type.rdf_source.yml index e6421392..64a9808e 100644 --- a/config/install/islandora.fedora_resource_type.rdf_source.yml +++ b/config/install/islandora.fedora_resource_type.rdf_source.yml @@ -1,4 +1,3 @@ langcode: en id: rdf_source label: 'RDF Source' -rdf_type: fedora:Resource \ No newline at end of file diff --git a/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml b/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml new file mode 100644 index 00000000..c26306a1 --- /dev/null +++ b/config/install/rdf.mapping.fedora_resource_type.rdf_source.yml @@ -0,0 +1,36 @@ +langcode: en +status: true +dependencies: + config: + - islandora.fedora_resource_type.rdf_source + module: + - islandora +id: fedora_resource_type.rdf_source +targetEntityType: fedora_resource_type +bundle: rdf_source +types: + - 'schema:Thing' + - 'ldp:RDFSource' + - 'ldp:Container' +fieldMappings: + title: + properties: + - 'dc11:title' + - 'rdf:label' + created: + properties: + - 'schema:dateCreated' + datatype_callback: + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' + changed: + properties: + - 'schema:dateModified' + datatype_callback: + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' + rdf_type: + properties: + - 'rdf:type' + uid: + properties: + - 'schema:author' + mapping_type: rel diff --git a/config/schema/fedora_resource_type.schema.yml b/config/schema/fedora_resource_type.schema.yml index e07cefa3..62d75a09 100644 --- a/config/schema/fedora_resource_type.schema.yml +++ b/config/schema/fedora_resource_type.schema.yml @@ -10,9 +10,6 @@ islandora.fedora_resource_type.*: label: 'Label' uuid: type: string - rdf_type: - type: label - label: 'RDF type' # Plugin \Drupal\islandora\Plugin\Search\FedoraResourceSearch search.plugin.node_search: diff --git a/fedora_resource.page.inc b/fedora_resource.page.inc index 0e2eb399..5b8171e6 100644 --- a/fedora_resource.page.inc +++ b/fedora_resource.page.inc @@ -5,8 +5,17 @@ * Contains fedora_resource.page.inc. * * Page callback for Fedora resource entities. + * + * This file is part of the Islandora Project. + * + * (c) Islandora Foundation + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @author Diego Pino Navarro https://github.com/diegopino + * */ - use Drupal\Core\Render\Element; use Drupal\Core\Link; use Drupal\Core\Url; @@ -48,7 +57,7 @@ function template_preprocess_fedora_resource_content_add_list(&$variables) { foreach ($variables['content'] as $type) { $variables['types'][$type->id()] = array( 'link' => Link::fromTextAndUrl($type->label(), new Url('entity.fedora_resource.add_form', array( - 'fedora_resource_type' => $type->id() + 'fedora_resource_type' => $type->id(), ), array('query' => $query))), 'description' => array( '#markup' => $type->label(), diff --git a/islandora.info.yml b/islandora.info.yml index 8883a00c..828e55a9 100644 --- a/islandora.info.yml +++ b/islandora.info.yml @@ -1,9 +1,9 @@ # This .info.yml files provides the basic information about our module to Drupal # More: https://www.drupal.org/node/2000204 -name: Islandora CLAW -description: 'Learning Drupal 8 with Islandora Claw' +name: 'islandora' +description: "Drupal 8 islandora claw playground" type: module -package: Islandora +package: islandora core: 8.x dependencies: - block @@ -11,4 +11,6 @@ dependencies: - path - text - options -version: '8.x-2.x-dev' \ No newline at end of file + - inline_entity_form + - jsonld +version: '8.x-1.x-dev' \ No newline at end of file diff --git a/islandora.links.action.yml b/islandora.links.action.yml index 38d9833a..2666c978 100644 --- a/islandora.links.action.yml +++ b/islandora.links.action.yml @@ -3,7 +3,6 @@ entity.fedora_resource.add_form: 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' diff --git a/islandora.links.task.yml b/islandora.links.task.yml index f55e9aa0..547e0758 100644 --- a/islandora.links.task.yml +++ b/islandora.links.task.yml @@ -14,4 +14,3 @@ entity.fedora_resource.delete_form: base_route: entity.fedora_resource.canonical title: Delete weight: 10 - diff --git a/islandora.module b/islandora.module index d858608d..39f3ff18 100644 --- a/islandora.module +++ b/islandora.module @@ -2,7 +2,16 @@ /** * @file - * Contains islandora.module.. + * Contains islandora.module. + * + * This file is part of the Islandora Project. + * + * (c) Islandora Foundation + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @author Diego Pino Navarro https://github.com/diegopino */ use Drupal\Core\Routing\RouteMatchInterface; @@ -56,3 +65,20 @@ function islandora_theme_suggestions_fedora_resource(array $variables) { $suggestions[] = 'fedora_resource__' . $entity->id() . '__' . $sanitized_view_mode; return $suggestions; } + +/** + * Implements hook_rdf_namespaces(). + */ +function islandora_rdf_namespaces() { + // Yes, it's amazing, rdf is not registered by default! + return array( + 'ldp' => 'http://www.w3.org/ns/ldp#', + 'dc11' => 'http://purl.org/dc/elements/1.1/', + 'nfo' => 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.1/', + 'ebucore' => 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#', + 'fedora' => 'http://fedora.info/definitions/v4/repository#', + 'owl' => 'http://www.w3.org/2002/07/owl#', + 'ore' => 'http://www.openarchives.org/ore/terms/', + 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + ); +} \ No newline at end of file diff --git a/islandora.routing.yml b/islandora.routing.yml index ef85e8a3..a228fc34 100644 --- a/islandora.routing.yml +++ b/islandora.routing.yml @@ -1,19 +1,12 @@ -entity.fedora_resource.collection: - path: '/admin/structure/fedora_resource' +# Islandora Routing definition +entity.fedora_resource_type.rdftest: + path: '/fedora_resource/{fedora_resource}/rdf' defaults: - _entity_list: 'fedora_resource' - _title: 'Fedora Resource' + _controller: '\Drupal\node\Controller\NodePreviewController::view' + _title_callback: '\Drupal\node\Controller\NodePreviewController::title' requirements: - _permission: 'administer fedora resource entities' + _node_preview_access: '{node_preview}' options: - _admin_route: true - -entity.fedora_resource_type.collection: - path: '/admin/structure/fedora_resource_type' - defaults: - _entity_list: 'fedora_resource_type' - _title: 'Fedora Resource Type' - requirements: - _permission: 'administer fedora resource type entities' - options: - _admin_route: true + parameters: + node_preview: + type: 'node_preview' \ No newline at end of file diff --git a/islandora.services.yml b/islandora.services.yml new file mode 100644 index 00000000..938de6ed --- /dev/null +++ b/islandora.services.yml @@ -0,0 +1,8 @@ +# Islandora Services +# islandora.services.yml: +services: + islandora.paramconverter.entity: + class: Drupal\islandora\ParamConverter\UuidEntityConverter + tags: + - { name: paramconverter } + arguments: ['@entity.manager'] diff --git a/src/Entity/FedoraResource.php b/src/Entity/FedoraResource.php index 9a7b0562..0e58567d 100644 --- a/src/Entity/FedoraResource.php +++ b/src/Entity/FedoraResource.php @@ -23,7 +23,7 @@ use Drupal\user\UserInterface; * "view_builder" = "Drupal\Core\Entity\EntityViewBuilder", * "list_builder" = "Drupal\islandora\FedoraResourceListBuilder", * "views_data" = "Drupal\islandora\Entity\FedoraResourceViewsData", - * + * "inline_form" = "Drupal\islandora\Form\FedoraResourceEntityInlineForm", * "form" = { * "default" = "Drupal\islandora\Form\FedoraResourceForm", * "add" = "Drupal\islandora\Form\FedoraResourceForm", @@ -52,22 +52,53 @@ use Drupal\user\UserInterface; * common_reference_target = TRUE, * permission_granularity = "bundle", * links = { - * "canonical" = "/admin/structure/fedora_resource/{fedora_resource}", - * "add-form" = "/admin/structure/fedora_resource/add/{fedora_resource_type}", - * "edit-form" = "/admin/structure/fedora_resource/{fedora_resource}/edit", - * "delete-form" = "/admin/structure/fedora_resource/{fedora_resource}/delete", + * "canonical" = "/fedora_resource/{fedora_resource}", + * "uuid" = "/islandora_uuid/{fedora_resource}", + * "add-form" = "/fedora_resource/add/{fedora_resource_type}", + * "edit-form" = "/fedora_resource/{fedora_resource}/edit", + * "delete-form" = "/fedora_resource/{fedora_resource}/delete", * "collection" = "/admin/structure/fedora_resource", - * "version-history" = "/admin/structure/{fedora_resource}/revisions", - * "revision" = "/admin/structure/{fedora_resource}/revisions/{node_revision}/view", * }, * bundle_entity_type = "fedora_resource_type", * field_ui_base_route = "entity.fedora_resource_type.edit_form" * ) */ -class FedoraResource extends ContentEntityBase implements FedoraResourceInterface { +class FedoraResource extends ContentEntityBase implements FedoraResourceInterface{ use EntityChangedTrait; + /** + * @param string $rel + * @param array $options + * @return $this|\Drupal\Core\Url + */ + public function toUrl($rel = 'canonical', array $options = []) { + // TODO: I Will override this to have a rel ='uuid' for islandora entities + return parent::toUrl($rel, $options); // TODO: Change the autogenerated stub + } + + /** + * Gets an array of placeholders for Fedora Resource Entity. + * + * We are overriding this method to add additional uuid + * placeholders. + * + * @param string $rel + * The link relationship type, for example: canonical or edit-form. + * + * @return array + * An array of URI placeholders. + */ + protected function urlRouteParameters($rel) { + $uri_route_parameters = parent::urlRouteParameters($rel); // TODO: Change the autogenerated stub + if ($rel === 'uuid') { + $uri_route_parameters[$this->getEntityTypeId()] = $this->uuid(); + } + return $uri_route_parameters; + + } + + /** * {@inheritdoc} */ @@ -175,8 +206,6 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac $this->set('status', $published ? NODE_PUBLISHED : NODE_NOT_PUBLISHED); return $this; } - - /** * {@inheritdoc} */ @@ -184,7 +213,6 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac { return ($this->get('fedora_has_parent') !== null); } - /** * {@inheritdoc} */ @@ -192,7 +220,6 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac { return $this->get('fedora_has_parent')->getEntity(); } - /** * {@inheritdoc} */ @@ -200,7 +227,6 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac { return $this->get('fedora_has_parent')->getEntity()->id(); } - /** * {@inheritdoc} */ @@ -219,9 +245,11 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac * An array of default values. */ public static function getFedoraRoot() { + // Just stub code, we need to figure out what "root is" in this context return array('root'); } + /** * {@inheritdoc} */ diff --git a/src/Entity/FedoraResourceType.php b/src/Entity/FedoraResourceType.php index 4303f59c..a777c563 100644 --- a/src/Entity/FedoraResourceType.php +++ b/src/Entity/FedoraResourceType.php @@ -31,7 +31,6 @@ use Drupal\islandora\FedoraResourceTypeInterface; * "uuid" = "uuid" * }, * links = { - * "canonical" = "/admin/structure/fedora_resource_type/{fedora_resource_type}", * "add-form" = "/admin/structure/fedora_resource_type/add", * "edit-form" = "/admin/structure/fedora_resource_type/{fedora_resource_type}/edit", * "delete-form" = "/admin/structure/fedora_resource_type/{fedora_resource_type}/delete", @@ -55,18 +54,4 @@ class FedoraResourceType extends ConfigEntityBundleBase implements FedoraResourc */ protected $label; - /** - * The RDF type - * - * @var string - */ - protected $rdf_type; - - /** - * {@inheritdoc} - */ - public function getRdfType() - { - return $this->rdf_type; - } } diff --git a/src/FedoraResourceAccessControlHandler.php b/src/FedoraResourceAccessControlHandler.php index e92cbd67..bb4f9e12 100644 --- a/src/FedoraResourceAccessControlHandler.php +++ b/src/FedoraResourceAccessControlHandler.php @@ -11,6 +11,7 @@ use Drupal\Core\Access\AccessResult; * Access controller for the Fedora resource entity. * * @see \Drupal\islandora\Entity\FedoraResource. + * @ingroup islandora */ class FedoraResourceAccessControlHandler extends EntityAccessControlHandler { diff --git a/src/FedoraResourceHtmlRouteProvider.php b/src/FedoraResourceHtmlRouteProvider.php index 958958fe..d5263e79 100644 --- a/src/FedoraResourceHtmlRouteProvider.php +++ b/src/FedoraResourceHtmlRouteProvider.php @@ -2,8 +2,10 @@ namespace Drupal\islandora; +use Drupal\Component\Uuid\Uuid; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider; +use Drupal\Core\Entity\Routing\EntityRouteProviderInterface; use Symfony\Component\Routing\Route; /** @@ -11,8 +13,9 @@ use Symfony\Component\Routing\Route; * * @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider * @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider + * @ingroup islandora */ -class FedoraResourceHtmlRouteProvider extends AdminHtmlRouteProvider { +class FedoraResourceHtmlRouteProvider extends AdminHtmlRouteProvider implements EntityRouteProviderInterface { /** * {@inheritdoc} @@ -37,9 +40,41 @@ class FedoraResourceHtmlRouteProvider extends AdminHtmlRouteProvider { $collection->add("$entity_type_id.settings", $settings_form_route); } + if ($uuid_route = $this->getUuidRoute($entity_type)) { + $collection->add("islandora.{$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' => 'fedora_resource.full', + '_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title', + ]) + ->setRequirement('_entity_access', $entity_type_id . '.view') + ->setOption('parameters', [ + $entity_type_id => ['type' => 'entity:' . $entity_type_id], + ]) + // Fetch UUID pattern from Uuid class(constant) + ->setRequirement($entity_type_id, '^' . Uuid::VALID_PATTERN . '$'); + return $route; + } + } + /** * Gets the collection route. * diff --git a/src/FedoraResourceTypeHtmlRouteProvider.php b/src/FedoraResourceTypeHtmlRouteProvider.php index cee288c9..38e54a0d 100644 --- a/src/FedoraResourceTypeHtmlRouteProvider.php +++ b/src/FedoraResourceTypeHtmlRouteProvider.php @@ -11,6 +11,7 @@ use Symfony\Component\Routing\Route; * * @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider * @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider + * @ingroup islandora */ class FedoraResourceTypeHtmlRouteProvider extends AdminHtmlRouteProvider { diff --git a/src/FedoraResourceTypeInterface.php b/src/FedoraResourceTypeInterface.php index ab9a6e54..c5e61d00 100644 --- a/src/FedoraResourceTypeInterface.php +++ b/src/FedoraResourceTypeInterface.php @@ -10,9 +10,4 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; interface FedoraResourceTypeInterface extends ConfigEntityInterface { // Add get/set methods for your configuration properties here. - - /** - * Return the entities rdf_type - */ - public function getRdfType(); } diff --git a/src/FedoraResourceTypeListBuilder.php b/src/FedoraResourceTypeListBuilder.php index e97afee4..3661177d 100644 --- a/src/FedoraResourceTypeListBuilder.php +++ b/src/FedoraResourceTypeListBuilder.php @@ -16,7 +16,6 @@ class FedoraResourceTypeListBuilder extends ConfigEntityListBuilder { public function buildHeader() { $header['label'] = $this->t('Fedora resource type'); $header['id'] = $this->t('Machine name'); - $header['rdf_type'] = $this->t('RDF Type'); return $header + parent::buildHeader(); } @@ -26,7 +25,6 @@ class FedoraResourceTypeListBuilder extends ConfigEntityListBuilder { public function buildRow(EntityInterface $entity) { $row['label'] = $entity->label(); $row['id'] = $entity->id(); - $row['rdf_type'] = $entity->getRdfType(); // You probably want a few more properties here... return $row + parent::buildRow($entity); } diff --git a/src/FedoraResourceViewBuilder.php b/src/FedoraResourceViewBuilder.php new file mode 100644 index 00000000..99c50a50 --- /dev/null +++ b/src/FedoraResourceViewBuilder.php @@ -0,0 +1,26 @@ +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 $entity_form + * The entity form. + * @param $form_state + * The form state of the parent form. + */ + 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 = array(); + 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/FedoraResourceTypeForm.php b/src/Form/FedoraResourceTypeForm.php index 0ed96565..ba36b360 100644 --- a/src/Form/FedoraResourceTypeForm.php +++ b/src/Form/FedoraResourceTypeForm.php @@ -37,15 +37,6 @@ class FedoraResourceTypeForm extends EntityForm { '#disabled' => !$fedora_resource_type->isNew(), ); - $form['rdf_type'] = array( - '#type' => 'textfield', - '#title' => $this->t('RDF Type'), - '#maxlength' => 255, - '#default_value' => $fedora_resource_type->getRdfType(), - '#description' => $this->t('Base RDF type for this entity'), - '#required' => TRUE, - ); - /* You will need additional form elements for your custom properties. */ return $form; diff --git a/src/ParamConverter/UuidEntityConverter.php b/src/ParamConverter/UuidEntityConverter.php new file mode 100644 index 00000000..b3e18b17 --- /dev/null +++ b/src/ParamConverter/UuidEntityConverter.php @@ -0,0 +1,69 @@ + https://github.com/diegopino + */ + +namespace Drupal\islandora\ParamConverter; + + +use Drupal\Core\ParamConverter\EntityConverter; +use Drupal\Core\ParamConverter\ParamConverterInterface; +use Drupal\Component\Uuid\Uuid; +use Symfony\Component\Routing\Route; +/** + * Converts an UUID param (route) into an Entity. + * + * @ingroup islandora + */ +class UuidEntityConverter extends EntityConverter implements ParamConverterInterface { + /** + * @inheritDoc + */ + public function convert($value, $definition, $name, array $defaults) { + + $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); + if ($storage = $this->entityManager->getStorage($entity_type_id)) { + + // Try to load fedora entity by UUID or ID depending on $value. + if (!(is_int($value) || ctype_digit((string) $value)) && Uuid::isValid($value)) { + $entities = $storage->loadByProperties(['uuid' => $value]); + $entity = ($entities) ? reset($entities) : NULL; + + } + else { + $entity = parent::convert($value, $definition, $name, $defaults); + } + } + + return $entity; + } + + /** + * @inheritDoc + */ + public function applies($definition, $name, Route $route) { + /*if (!empty($definition['type']) && strpos($definition['type'], 'entity:') === 0) { + $entity_type_id = substr($definition['type'], strlen('entity:')); + if (strpos($definition['type'], '{') !== FALSE) { + $entity_type_slug = substr($entity_type_id, 1, -1); + return $name != $entity_type_slug && in_array($entity_type_slug, $route->compile()->getVariables(), TRUE); + } + return $this->entityManager->hasDefinition($entity_type_id); + } + return FALSE;*/ + + return parent::applies($definition, $name, $route); // TODO: Change the autogenerated stub + } + + +} \ No newline at end of file