Skip to content

Commit

Permalink
Fix/batch upload children, with validation according to default widget (
Browse files Browse the repository at this point in the history
Islandora#896)

* Add ctools, prior to using it.

* Fix up all the dependency references.

... before the colon is the project name, so should only be "drupal" for
modules shipped in core.

* Some more together.

* Decent progress... getting things actually rendering...

... bit of refactoring stuff making a mess.

* More worky.

... as in, basically functional. Still needs coding standards pass, and
testing with more/all types of content.

* Coding standards, and warning of validation issues.

* Pull the batch out to a separate service.

* Something of namespacing the child-specific batch...

... 'cause need to slap together a media-specific batch similarly?

* All together, I think...

Both the child-uploading, and media-uploading forms.

* It is not necessary to explicitly mark the files as permanent.

* Further generalizing...

... no longer necessarily trying to load files, where files might not
be present (for non-file media... oEmbed things?).

* Adjust class comment.

* Get rid of the deprecation flags.

* Remove unused constant.

... is defined instead at the "FileSelectionForm" level, accidentally
left it here from intermediate implementation state.

* Pass the renderer along, with the version constraint.

* Add update hook to enable ctools in sites where it may not be.

... as it's now required.

* Cover ALL the exits.

* Refine message.

* Excessively long line in comment...

... whoops.

* Bump spec up to allow ctools 4.

Gave it a run through here, and seemed to work fine; however, ctools'
project page still seems to suggest the 3 major version should be
preferred... but let's allow 4, if people are using or want to test it
out?

* Fix undefined "count" index.
  • Loading branch information
adam-vessey authored and rosiel committed Dec 14, 2022
1 parent ebe9829 commit 77fd427
Show file tree
Hide file tree
Showing 21 changed files with 1,441 additions and 21 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"drupal/token" : "^1.3",
"drupal/flysystem" : "^2.0@beta",
"islandora/crayfish-commons": "^2",
"drupal/file_replace": "^1.1"
"drupal/file_replace": "^1.1",
"drupal/ctools": "^3.8 || ^4"
},
"require-dev": {
"phpunit/phpunit": "^6",
Expand All @@ -37,7 +38,7 @@
"sebastian/phpcpd": "*"
},
"suggest": {
"drupal/transliterate_filenames": "Sanitizes filenames when they are uploaded so they don't break your repository."
"drupal/transliterate_filenames": "Sanitizes filenames when they are uploaded so they don't break your repository."
},
"license": "GPL-2.0-or-later",
"authors": [
Expand Down
25 changes: 13 additions & 12 deletions islandora.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ dependencies:
- drupal:text
- drupal:options
- drupal:link
- drupal:jsonld
- drupal:search_api
- drupal:jwt
- jsonld:jsonld
- search_api:search_api
- jwt:jwt
- drupal:rest
- drupal:filehash
- filehash:filehash
- drupal:basic_auth
- drupal:context_ui
- context:context_ui
- drupal:action
- drupal:eva
- eva:eva
- drupal:taxonomy
- drupal:views_ui
- drupal:media
- drupal:prepopulate
- drupal:features_ui
- drupal:migrate_source_csv
- prepopulate:prepopulate
- features:features_ui
- migrate_source_csv:migrate_source_csv
- drupal:content_translation
- drupal:flysystem
- drupal:token
- drupal:file_replace
- flysystem:flysystem
- token:token
- file_replace:file_replace
- ctools:ctools
38 changes: 38 additions & 0 deletions islandora.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Install/update hook implementations.
*/

use Drupal\Core\Extension\ExtensionNameLengthException;
use Drupal\Core\Extension\MissingDependencyException;
use Drupal\Core\Utility\UpdateException;

/**
* Adds common namespaces to jsonld.settings.
*/
Expand Down Expand Up @@ -174,3 +178,37 @@ function update_jsonld_included_namespaces() {
->warning("Could not find required jsonld.settings to add default RDF namespaces.");
}
}

/**
* Ensure that ctools is enabled.
*/
function islandora_update_8007() {
$module_handler = \Drupal::moduleHandler();
if ($module_handler->moduleExists('ctools')) {
return t('The "@module_name" module is already enabled, no action necessary.', [
'@module_name' => 'ctools',
]);
}

/** @var \Drupal\Core\Extension\ModuleInstallerInterface $installer */
$installer = \Drupal::service('module_installer');

try {
if ($installer->install(['ctools'], TRUE)) {
return t('The "@module_name" module was enabled successfully.', [
'@module_name' => 'ctools',
]);
}
}
catch (ExtensionNameLengthException | MissingDependencyException $e) {
throw new UpdateException('Failed; ensure that the ctools module is available in the Drupal installation.', 0, $e);
}
catch (\Exception $e) {
throw new UpdateException('Failed; encountered an exception while trying to enable ctools.', 0, $e);
}

// Theoretically impossible to hit, as ModuleInstaller::install() only returns
// TRUE (or throws/propagates an exception), but... probably a good idea to
// have the here, just in case?
throw new UpdateException('Failed; hit the end of the update hook implementation, which is not expected.');
}
14 changes: 8 additions & 6 deletions islandora.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ islandora.add_member_to_node_page:
_entity_create_any_access: 'node'

islandora.upload_children:
path: '/node/{node}/members/upload'
path: '/node/{node}/members/upload/{step}'
defaults:
_form: '\Drupal\islandora\Form\AddChildrenForm'
_wizard: '\Drupal\islandora\Form\AddChildrenWizard\ChildForm'
_title: 'Upload Children'
step: 'type_selection'
options:
_admin_route: 'TRUE'
requirements:
_custom_access: '\Drupal\islandora\Form\AddChildrenForm::access'
_custom_access: '\Drupal\islandora\Form\AddChildrenWizard\Access::childAccess'

islandora.add_media_to_node_page:
path: '/node/{node}/media/add'
Expand All @@ -58,14 +59,15 @@ islandora.add_media_to_node_page:
_entity_create_any_access: 'media'

islandora.upload_media:
path: '/node/{node}/media/upload'
path: '/node/{node}/media/upload/{step}'
defaults:
_form: '\Drupal\islandora\Form\AddMediaForm'
_wizard: '\Drupal\islandora\Form\AddChildrenWizard\MediaForm'
_title: 'Add media'
step: 'type_selection'
options:
_admin_route: 'TRUE'
requirements:
_custom_access: '\Drupal\islandora\Form\AddMediaForm::access'
_custom_access: '\Drupal\islandora\Form\AddChildrenWizard\Access::mediaAccess'

islandora.media_source_update:
path: '/media/{media}/source'
Expand Down
16 changes: 16 additions & 0 deletions islandora.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,19 @@ services:
arguments: ['@jwt.authentication.jwt']
tags:
- { name: event_subscriber }
islandora.upload_children.batch_processor:
class: Drupal\islandora\Form\AddChildrenWizard\ChildBatchProcessor
arguments:
- '@entity_type.manager'
- '@database'
- '@current_user'
- '@messenger'
- '@date.formatter'
islandora.upload_media.batch_processor:
class: Drupal\islandora\Form\AddChildrenWizard\MediaBatchProcessor
arguments:
- '@entity_type.manager'
- '@database'
- '@current_user'
- '@messenger'
- '@date.formatter'
2 changes: 1 addition & 1 deletion src/Form/AddChildrenForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function buildNodeFinished($success, $results, $operations) {
* @param \Drupal\Core\Routing\RouteMatch $route_match
* The current routing match.
*
* @return \Drupal\Core\Access\AccessResultAllowed|\Drupal\Core\Access\AccessResultForbidden
* @return \Drupal\Core\Access\AccessResultInterface
* Whether we can or can't show the "thing".
*/
public function access(RouteMatch $route_match) {
Expand Down
Loading

0 comments on commit 77fd427

Please sign in to comment.