Skip to content

Commit

Permalink
Upload form (Islandora#754)
Browse files Browse the repository at this point in the history
* Upload form

* Missing var doc comment

* Manage Collections Page

* Getting rid of stuff in other PRs

* Adapting form to be in line with proposed modeling changes

* Cleaning up settings form schema

* Removing duplicate helper function

* Update ManageMembersController.php

* Coding standards, copy/paste detector (embarassing...)

* Apparantly i don't know how pass-by-reference works

* Incorrectly named config key.  Sadly confusing :(

* s/field_tags/field_model

* Fixing phpunit annotations that point to non-existant classes

* Foiled by a newline

* Wrong class for access function

* Renaming links to say 'Batch Upload'

* Letting user select media type instead of guessing
  • Loading branch information
dannylamb authored May 5, 2021
1 parent 07178e9 commit 5127e7f
Show file tree
Hide file tree
Showing 15 changed files with 891 additions and 32 deletions.
6 changes: 6 additions & 0 deletions config/schema/islandora.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ islandora.settings:
jwt_expiry:
type: string
label: 'How long JWTs should last before expiring.'
upload_form_location:
type: string
label: 'Upload Form Location'
upload_form_allowed_mimetypes:
type: string
label: 'Upload Form Allowed Extensions'
gemini_url:
type: uri
label: 'Url to Gemini microservice'
Expand Down
16 changes: 14 additions & 2 deletions islandora.links.action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
islandora.upload_media:
route_name: islandora.upload_media
title: Batch Upload Media
appears_on:
- view.media_of.page_1

islandora.add_media_to_node:
route_name: islandora.add_media_to_node_page
title: Add media
title: Add Media
appears_on:
- view.media_of.page_1

islandora.upload_children:
route_name: islandora.upload_children
title: Batch Upload Children
appears_on:
- view.manage_members.page_1

islandora.add_member_to_node:
route_name: islandora.add_member_to_node_page
title: Add child
title: Add Child
appears_on:
- view.manage_members.page_1

Expand Down
21 changes: 21 additions & 0 deletions islandora.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ islandora.add_member_to_node_page:
requirements:
_entity_create_any_access: 'node'

islandora.upload_children:
path: '/node/{node}/members/upload'
defaults:
_form: '\Drupal\islandora\Form\AddChildrenForm'
_title: 'Upload Children'
options:
_admin_route: 'TRUE'
requirements:
_access: 'TRUE'
#_permssion: 'create node,create media'

islandora.add_media_to_node_page:
path: '/node/{node}/media/add'
defaults:
Expand All @@ -47,6 +58,16 @@ islandora.add_media_to_node_page:
requirements:
_entity_create_any_access: 'media'

islandora.upload_media:
path: '/node/{node}/media/upload'
defaults:
_form: '\Drupal\islandora\Form\AddMediaForm'
_title: 'Add media'
options:
_admin_route: 'TRUE'
requirements:
_custom_access: '\Drupal\islandora\Form\AddMediaForm::access'

islandora.media_source_update:
path: '/media/{media}/source'
defaults:
Expand Down
9 changes: 6 additions & 3 deletions src/Controller/ManageMediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\islandora\Controller;

use Drupal\islandora\IslandoraUtils;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\RouteMatch;
use Drupal\node\Entity\Node;
Expand All @@ -22,13 +23,15 @@ class ManageMediaController extends ManageMembersController {
* Array of media types to add.
*/
public function addToNodePage(NodeInterface $node) {
$field = IslandoraUtils::MEDIA_OF_FIELD;

return $this->generateTypeList(
'media',
'media_type',
'entity.media.add_form',
'entity.media_type.add_form',
$node,
'field_media_of'
$field,
['query' => ["edit[$field][widget][0][target_id]" => $node->id()]]
);
}

Expand All @@ -47,7 +50,7 @@ public function access(RouteMatch $route_match) {
if (!$node instanceof NodeInterface) {
$node = Node::load($node);
}
if ($node->hasField('field_model') && $node->hasField('field_member_of')) {
if ($this->utils->isIslandoraType($node->getEntityTypeId(), $node->bundle())) {
return AccessResult::allowed();
}
}
Expand Down
26 changes: 20 additions & 6 deletions src/Controller/ManageMembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Entity\Controller\EntityController;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Link;
use Drupal\islandora\IslandoraUtils;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -36,6 +37,13 @@ class ManageMembersController extends EntityController {
*/
protected $renderer;

/**
* Islandora Utils.
*
* @var \Drupal\islandora\IslandoraUtils
*/
protected $utils;

/**
* Constructor.
*
Expand All @@ -45,15 +53,19 @@ class ManageMembersController extends EntityController {
* The entity field manager.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Drupal\islandora\IslandoraUtils $utils
* Islandora utils.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
EntityFieldManagerInterface $entity_field_manager,
RendererInterface $renderer
RendererInterface $renderer,
IslandoraUtils $utils
) {
$this->entityTypeManager = $entity_type_manager;
$this->entityFieldManager = $entity_field_manager;
$this->renderer = $renderer;
$this->utils = $utils;
}

/**
Expand All @@ -63,7 +75,8 @@ public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager'),
$container->get('entity_field.manager'),
$container->get('renderer')
$container->get('renderer'),
$container->get('islandora.utils')
);
}

Expand All @@ -74,20 +87,21 @@ public static function create(ContainerInterface $container) {
* Node you want to add a member to.
*/
public function addToNodePage(NodeInterface $node) {
$field = IslandoraUtils::MEMBER_OF_FIELD;
return $this->generateTypeList(
'node',
'node_type',
'node.add',
'node.type_add',
$node,
'field_member_of'
$field,
['query' => ["edit[$field][widget][0][target_id]" => $node->id()]]
);
}

/**
* Renders a list of content types to add as members.
*/
protected function generateTypeList($entity_type, $bundle_type, $entity_add_form, $bundle_add_form, NodeInterface $node, $field) {
protected function generateTypeList($entity_type, $bundle_type, $entity_add_form, $bundle_add_form, $field, array $url_options) {
$type_definition = $this->entityTypeManager->getDefinition($bundle_type);

$build = [
Expand Down Expand Up @@ -115,7 +129,7 @@ protected function generateTypeList($entity_type, $bundle_type, $entity_add_form
$bundle->label(),
$entity_add_form,
[$bundle_type => $bundle->id()],
['query' => ["edit[$field][widget][0][target_id]" => $node->id()]]
$url_options
),
];
}
Expand Down
Loading

0 comments on commit 5127e7f

Please sign in to comment.