Browse Source
* Sprint Sept 2016 Huge Pull Request, Highlights: * removed rdf_type from fedora_source_type entity, better to handle this via rdfmapping based on bundle rdf assignment * Added inline form support * Added default rdf namespace register * Added test rdf.map config entity (have to check if it’s working, probably some typo? * Added experimental UUID Entity Solver(service, route and @annotation link * Made jsonld serialiser (github.com/diegopino/claw-jsonld) a requirement * Some route cleanups * Updated to correct Branch * Bad cherry picked Double method declaration after cherry picking, fixed.pull/756/head
Diego Pino Navarro
8 years ago
committed by
dannylamb
23 changed files with 576 additions and 77 deletions
@ -1 +1,25 @@
|
||||
# claw-drupal8 |
||||
# 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) |
@ -1,4 +1,3 @@
|
||||
langcode: en |
||||
id: non_rdf_source |
||||
label: 'Non RDF Source' |
||||
rdf_type: fedora:Binary |
@ -1,4 +1,3 @@
|
||||
langcode: en |
||||
id: rdf_source |
||||
label: 'RDF Source' |
||||
rdf_type: fedora:Resource |
@ -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 |
@ -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' |
@ -0,0 +1,8 @@
|
||||
# Islandora Services |
||||
# islandora.services.yml: |
||||
services: |
||||
islandora.paramconverter.entity: |
||||
class: Drupal\islandora\ParamConverter\UuidEntityConverter |
||||
tags: |
||||
- { name: paramconverter } |
||||
arguments: ['@entity.manager'] |
@ -0,0 +1,26 @@
|
||||
<?php |
||||
/** |
||||
* Created by PhpStorm. |
||||
* User: dpino |
||||
* Date: 8/16/16 |
||||
* Time: 11:49 PM |
||||
*/ |
||||
|
||||
namespace Drupal\islandora; |
||||
|
||||
|
||||
use Drupal\node\NodeViewBuilder; |
||||
|
||||
/** |
||||
* Class FedoraResourceViewBuilder |
||||
* view builder handler. |
||||
* |
||||
* @TODO this should manage how fedora_resource are build to be viewed. |
||||
* |
||||
* Right now we are just using Drupal\Core\Entity\EntityViewBuilder |
||||
* @ingroup islandora |
||||
*/ |
||||
class FedoraResourceViewBuilder extends NodeViewBuilder { |
||||
|
||||
|
||||
} |
@ -0,0 +1,279 @@
|
||||
<?php |
||||
|
||||
namespace Drupal\islandora\Form; |
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface; |
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay; |
||||
use Drupal\Core\Entity\EntityInterface; |
||||
use Drupal\Core\Entity\EntityFieldManagerInterface; |
||||
use Drupal\Core\Entity\EntityTypeInterface; |
||||
use Drupal\Core\Entity\EntityTypeManagerInterface; |
||||
use Drupal\Core\Extension\ModuleHandlerInterface; |
||||
use Drupal\Core\Field\WidgetBase; |
||||
use Drupal\Core\Form\FormStateInterface; |
||||
use Drupal\inline_entity_form\Form\EntityInlineForm; |
||||
use Drupal\inline_entity_form\InlineFormInterface; |
||||
use Symfony\Component\DependencyInjection\ContainerInterface; |
||||
|
||||
/** |
||||
* Generic entity inline form handler. |
||||
*/ |
||||
class FedoraResourceEntityInlineForm extends EntityInlineForm implements InlineFormInterface { |
||||
|
||||
/** |
||||
* The entity field manager. |
||||
* |
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface |
||||
*/ |
||||
protected $entityFieldManager; |
||||
|
||||
/** |
||||
* The entity type manager. |
||||
* |
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface |
||||
*/ |
||||
protected $entityTypeManager; |
||||
|
||||
/** |
||||
* The entity type managed by this handler. |
||||
* |
||||
* @var \Drupal\Core\Entity\EntityTypeInterface |
||||
*/ |
||||
protected $entityType; |
||||
|
||||
/** |
||||
* Module handler service. |
||||
* |
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface |
||||
*/ |
||||
protected $moduleHandler; |
||||
|
||||
/** |
||||
* Constructs the inline entity form controller. |
||||
* |
||||
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager |
||||
* The entity field manager. |
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
||||
* The entity type manager. |
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler |
||||
* The module handler. |
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type |
||||
* The entity type. |
||||
*/ |
||||
public function __construct(EntityFieldManagerInterface $entity_field_manager, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, EntityTypeInterface $entity_type) { |
||||
$this->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); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,69 @@
|
||||
<?php |
||||
/** |
||||
* @file |
||||
* Contains UuidEntityConverter.php |
||||
* |
||||
* 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 <dpino@metro.org> 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 |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue