Skip to content

Commit dcad946

Browse files
adam-vesseyrosiel
authored andcommitted
Fix/batch upload children, with validation according to default widget (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.
1 parent ed432a3 commit dcad946

21 files changed

+1441
-21
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"drupal/token" : "^1.3",
2929
"drupal/flysystem" : "^2.0@alpha",
3030
"islandora/crayfish-commons": "^2",
31-
"drupal/file_replace": "^1.1"
31+
"drupal/file_replace": "^1.1",
32+
"drupal/ctools": "^3.8 || ^4"
3233
},
3334
"require-dev": {
3435
"phpunit/phpunit": "^6",
@@ -37,7 +38,7 @@
3738
"sebastian/phpcpd": "*"
3839
},
3940
"suggest": {
40-
"drupal/transliterate_filenames": "Sanitizes filenames when they are uploaded so they don't break your repository."
41+
"drupal/transliterate_filenames": "Sanitizes filenames when they are uploaded so they don't break your repository."
4142
},
4243
"license": "GPL-2.0-or-later",
4344
"authors": [

islandora.info.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@ dependencies:
1313
- drupal:text
1414
- drupal:options
1515
- drupal:link
16-
- drupal:jsonld
17-
- drupal:search_api
18-
- drupal:jwt
16+
- jsonld:jsonld
17+
- search_api:search_api
18+
- jwt:jwt
1919
- drupal:rest
20-
- drupal:filehash
20+
- filehash:filehash
2121
- drupal:basic_auth
22-
- drupal:context_ui
22+
- context:context_ui
2323
- drupal:action
24-
- drupal:eva
24+
- eva:eva
2525
- drupal:taxonomy
2626
- drupal:views_ui
2727
- drupal:media
28-
- drupal:prepopulate
29-
- drupal:features_ui
30-
- drupal:migrate_source_csv
28+
- prepopulate:prepopulate
29+
- features:features_ui
30+
- migrate_source_csv:migrate_source_csv
3131
- drupal:content_translation
32-
- drupal:flysystem
33-
- drupal:token
34-
- drupal:file_replace
32+
- flysystem:flysystem
33+
- token:token
34+
- file_replace:file_replace
35+
- ctools:ctools

islandora.install

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* Install/update hook implementations.
66
*/
77

8+
use Drupal\Core\Extension\ExtensionNameLengthException;
9+
use Drupal\Core\Extension\MissingDependencyException;
10+
use Drupal\Core\Utility\UpdateException;
11+
812
/**
913
* Adds common namespaces to jsonld.settings.
1014
*/
@@ -174,3 +178,37 @@ function update_jsonld_included_namespaces() {
174178
->warning("Could not find required jsonld.settings to add default RDF namespaces.");
175179
}
176180
}
181+
182+
/**
183+
* Ensure that ctools is enabled.
184+
*/
185+
function islandora_update_8007() {
186+
$module_handler = \Drupal::moduleHandler();
187+
if ($module_handler->moduleExists('ctools')) {
188+
return t('The "@module_name" module is already enabled, no action necessary.', [
189+
'@module_name' => 'ctools',
190+
]);
191+
}
192+
193+
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $installer */
194+
$installer = \Drupal::service('module_installer');
195+
196+
try {
197+
if ($installer->install(['ctools'], TRUE)) {
198+
return t('The "@module_name" module was enabled successfully.', [
199+
'@module_name' => 'ctools',
200+
]);
201+
}
202+
}
203+
catch (ExtensionNameLengthException | MissingDependencyException $e) {
204+
throw new UpdateException('Failed; ensure that the ctools module is available in the Drupal installation.', 0, $e);
205+
}
206+
catch (\Exception $e) {
207+
throw new UpdateException('Failed; encountered an exception while trying to enable ctools.', 0, $e);
208+
}
209+
210+
// Theoretically impossible to hit, as ModuleInstaller::install() only returns
211+
// TRUE (or throws/propagates an exception), but... probably a good idea to
212+
// have the here, just in case?
213+
throw new UpdateException('Failed; hit the end of the update hook implementation, which is not expected.');
214+
}

islandora.routing.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ islandora.add_member_to_node_page:
3737
_entity_create_any_access: 'node'
3838

3939
islandora.upload_children:
40-
path: '/node/{node}/members/upload'
40+
path: '/node/{node}/members/upload/{step}'
4141
defaults:
42-
_form: '\Drupal\islandora\Form\AddChildrenForm'
42+
_wizard: '\Drupal\islandora\Form\AddChildrenWizard\ChildForm'
4343
_title: 'Upload Children'
44+
step: 'type_selection'
4445
options:
4546
_admin_route: 'TRUE'
4647
requirements:
47-
_custom_access: '\Drupal\islandora\Form\AddChildrenForm::access'
48+
_custom_access: '\Drupal\islandora\Form\AddChildrenWizard\Access::childAccess'
4849

4950
islandora.add_media_to_node_page:
5051
path: '/node/{node}/media/add'
@@ -58,14 +59,15 @@ islandora.add_media_to_node_page:
5859
_entity_create_any_access: 'media'
5960

6061
islandora.upload_media:
61-
path: '/node/{node}/media/upload'
62+
path: '/node/{node}/media/upload/{step}'
6263
defaults:
63-
_form: '\Drupal\islandora\Form\AddMediaForm'
64+
_wizard: '\Drupal\islandora\Form\AddChildrenWizard\MediaForm'
6465
_title: 'Add media'
66+
step: 'type_selection'
6567
options:
6668
_admin_route: 'TRUE'
6769
requirements:
68-
_custom_access: '\Drupal\islandora\Form\AddMediaForm::access'
70+
_custom_access: '\Drupal\islandora\Form\AddChildrenWizard\Access::mediaAccess'
6971

7072
islandora.media_source_update:
7173
path: '/media/{media}/source'

islandora.services.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,19 @@ services:
5959
arguments: ['@jwt.authentication.jwt']
6060
tags:
6161
- { name: event_subscriber }
62+
islandora.upload_children.batch_processor:
63+
class: Drupal\islandora\Form\AddChildrenWizard\ChildBatchProcessor
64+
arguments:
65+
- '@entity_type.manager'
66+
- '@database'
67+
- '@current_user'
68+
- '@messenger'
69+
- '@date.formatter'
70+
islandora.upload_media.batch_processor:
71+
class: Drupal\islandora\Form\AddChildrenWizard\MediaBatchProcessor
72+
arguments:
73+
- '@entity_type.manager'
74+
- '@database'
75+
- '@current_user'
76+
- '@messenger'
77+
- '@date.formatter'

src/Form/AddChildrenForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function buildNodeFinished($success, $results, $operations) {
229229
* @param \Drupal\Core\Routing\RouteMatch $route_match
230230
* The current routing match.
231231
*
232-
* @return \Drupal\Core\Access\AccessResultAllowed|\Drupal\Core\Access\AccessResultForbidden
232+
* @return \Drupal\Core\Access\AccessResultInterface
233233
* Whether we can or can't show the "thing".
234234
*/
235235
public function access(RouteMatch $route_match) {

0 commit comments

Comments
 (0)