diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index 79e3d9e14..7ea214f2c 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -375,11 +375,9 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = $viewers = array_merge_recursive($no_viewer, $viewers); } // @FIXME -// // @FIXME -// // The correct configuration object could not be determined. You'll need to -// // rewrite this call manually. -// $viewers_config = variable_get($variable_id, array()); - + // The correct configuration object could not be determined. You'll need to + // rewrite this call manually. + // $viewers_config = variable_get($variable_id, array()); $form['viewers'] = [ '#type' => 'fieldset', '#title' => t('Viewers'), @@ -409,29 +407,31 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = '#markup' => $profile['description'], ]; // @FIXME -// l() expects a Url object, created from a route name or external URI. -// $form['viewers'][$variable_id]['configuration'][$name] = array( -// '#type' => 'item', -// '#markup' => (isset($profile['configuration']) AND $profile['configuration'] != '') ? l(t('configure'), $profile['configuration']) : '', -// ); - + // l() expects a Url object, created from a route name or external URI. + // @codingStandardsIgnoreStart + // $form['viewers'][$variable_id]['configuration'][$name] = [ + // '#type' => 'item', + // '#markup' => (isset($profile['configuration']) AND $profile['configuration'] != '') ? l(t('configure'), $profile['configuration']) : '', + // ]; + // @codingStandardsIgnoreEnd } $form['viewers'][$variable_id]['default'] = [ '#type' => 'radios', '#options' => isset($options) ? $options : [], + // @codingStandardsIgnoreStart '#default_value' => !empty($viewers_config) ? $viewers_config['default'] : 'none', + // @codingStandardsIgnoreEnd ]; } else { $form['viewers'][$variable_id . '_no_viewers'] = [ '#markup' => t('No viewers detected.'), ]; - // @FIXME -// // @FIXME -// // The correct configuration object could not be determined. You'll need to -// // rewrite this call manually. -// variable_del($variable_id); + // @FIXME + // The correct configuration object could not be determined. You'll need to + // rewrite this call manually. + // variable_del($variable_id); } return $form; } @@ -482,6 +482,8 @@ function islandora_get_viewers(array $mimetype = [], $content_model = NULL) { */ function theme_islandora_viewers_table($variables) { $form = $variables['form']; + // @codingStandardsIgnoreStart + // XXX Usage is commented out below. $rows = []; foreach ($form['name'] as $key => $element) { if (is_array($element) && \Drupal\Core\Render\Element::child($key)) { @@ -493,27 +495,32 @@ function theme_islandora_viewers_table($variables) { $rows[] = ['data' => $row]; } } + // @codingStandardsIgnoreEnd + // @codingStandardsIgnoreStart + // XXX Usage is commented out below. $header = []; $header[] = ['data' => t('Default')]; $header[] = ['data' => t('Label')]; $header[] = ['data' => t('Description')]; $header[] = ['data' => t('Configuration')]; - + // @codingStandardsIgnoreEnd $output = ''; // @FIXME -// theme() has been renamed to _theme() and should NEVER be called directly. -// Calling _theme() directly can alter the expected output and potentially -// introduce security issues (see https://www.drupal.org/node/2195739). You -// should use renderable arrays instead. -// -// -// @see https://www.drupal.org/node/2195739 -// $output .= theme('table', array( -// 'header' => $header, -// 'rows' => $rows, -// 'attributes' => array('id' => 'islandora-viewers-table'), -// )); - + // theme() has been renamed to _theme() and should NEVER be called directly. + // Calling _theme() directly can alter the expected output and potentially + // introduce security issues (see https://www.drupal.org/node/2195739). You + // should use renderable arrays instead. + // + // Remove coding standard annotations above. + // + // @see https://www.drupal.org/node/2195739 + // @codingStandardsIgnoreStart + // $output .= theme('table', array( + // 'header' => $header, + // 'rows' => $rows, + // 'attributes' => array('id' => 'islandora-viewers-table'), + // )); + // @codingStandardsIgnoreEnd $output .= drupal_render_children($form); return $output; } @@ -521,8 +528,9 @@ function theme_islandora_viewers_table($variables) { /** * Gather information and return a rendered viewer. * - * @param array/string $params - * Array or string with data the module needs in order to render a full viewer. + * @param mixed $params + * Array or string with data the module needs in order to render a full + * viewer. * @param string $variable_id * The id of the Drupal variable the viewer settings are saved in. * @param AbstractObject $fedora_object @@ -532,13 +540,14 @@ function theme_islandora_viewers_table($variables) { * The callback to the viewer module. Returns a rendered viewer. Returns FALSE * if no viewer is set. */ -function islandora_get_viewer($params = NULL, $variable_id = NULL, $fedora_object = NULL) { - // @FIXME -// // @FIXME -// // The correct configuration object could not be determined. You'll need to -// // rewrite this call manually. -// $settings = variable_get($variable_id, array()); +function islandora_get_viewer($params = NULL, $variable_id = NULL, AbstractObject $fedora_object = NULL) { + // @FIXME + // The correct configuration object could not be determined. You'll need to + // rewrite this call manually. + // $settings = variable_get($variable_id, array()); + // @codingStandardsIgnoreStart + // XXX $settings is commented out and thus undefined. if (!empty($settings) and $settings['default'] !== 'none') { $viewer_id = islandora_get_viewer_id($variable_id); if ($viewer_id and $params !== NULL) { @@ -548,6 +557,7 @@ function islandora_get_viewer($params = NULL, $variable_id = NULL, $fedora_objec } } } + // @codingStandardsIgnoreEnd return FALSE; } @@ -561,15 +571,17 @@ function islandora_get_viewer($params = NULL, $variable_id = NULL, $fedora_objec * The enabled viewer id. Returns FALSE if no viewer config is set. */ function islandora_get_viewer_id($variable_id) { - // @FIXME -// // @FIXME -// // The correct configuration object could not be determined. You'll need to -// // rewrite this call manually. -// $viewers_config = variable_get($variable_id, array()); + // @FIXME + // The correct configuration object could not be determined. You'll need to + // rewrite this call manually. + // $viewers_config = variable_get($variable_id, array()); + // @codingStandardsIgnoreStart + // XXX $viewers_config is undefined, commented out above. if (!empty($viewers_config)) { return $viewers_config['default']; } + // @codingStandardsIgnoreEnd return FALSE; } diff --git a/includes/tuque.inc b/includes/tuque.inc index 11227bce6..2e67a91fa 100644 --- a/includes/tuque.inc +++ b/includes/tuque.inc @@ -18,8 +18,16 @@ use Drupal\user\Entity\User; /** * A class to include the Tuque library. + * + * @codingStandardsIgnoreStart + * XXX: Poorly implemented sniff indicates class should begin with + * "Islandora.info" instead of just "Islandora"... ideally, this should move + * somewhere under the Drupal\islandora\Tuque namespace at somepoint... + * Possibly as a service such that Dependency Injection can happen as + * necessary. */ class IslandoraTuque { +// @codingStandardsIgnoreEnd /** * Connection to the repository. diff --git a/includes/utilities.inc b/includes/utilities.inc index 7a4e40ecc..d28fe042b 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -484,7 +484,7 @@ function islandora_get_datastreams_requirements_from_content_model(AbstractObjec * @return NewFedoraObject * An ingestable NewFedoraObject. */ -function islandora_prepare_new_object($name_source = NULL, $label = NULL, $datastreams = [], $content_models = [], $relationships = []) { +function islandora_prepare_new_object($name_source = NULL, $label = NULL, array $datastreams = [], array $content_models = [], array $relationships = []) { $user = \Drupal::currentUser(); $tuque = islandora_get_tuque_connection(); $object = isset($name_source) ? $tuque->repository->constructObject($name_source) : new IslandoraNewFedoraObject(NULL, $tuque->repository); @@ -529,10 +529,7 @@ function islandora_prepare_new_object($name_source = NULL, $label = NULL, $datas // Schema does not match available php stream wrapper. Attempt to // set datastream_file by url for the given scheme. Https (SSL) can // cause this to fail, and trigger an output log in watchdog. - // @FIXME -// url() expects a route name or an external URI. -// $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); - \Drupal::logger('islandora')->warning('Attempting to ingest %file in islandora_prepare_new_object(), but it does not appear to be readable. We will pass the path through url(), and pass along as such.', array('%file' => $datastream_file)); + throw new Exception('Unsupported operation: Attempted to ingest non-readable file as datastream.'); } } @@ -597,7 +594,7 @@ function islandora_executable_available_message($path, $version = NULL, $require if ($available) { $image = [ '#theme' => 'image', - '#uri' =>'/core/misc/icons/73b355/check.svg' , + '#uri' => '/core/misc/icons/73b355/check.svg', ]; $message = t('Executable found at @path', ['@path' => $path]); if ($version) { @@ -607,7 +604,7 @@ function islandora_executable_available_message($path, $version = NULL, $require if (version_compare($version, $required_version) < 0) { $image = [ '#theme' => 'image', - '#uri' =>'/core/misc/icons/e32700/error.svg' , + '#uri' => '/core/misc/icons/e32700/error.svg', ]; } $message .= t('
Required Version: @version', ['@version' => $required_version]); @@ -616,7 +613,7 @@ function islandora_executable_available_message($path, $version = NULL, $require else { $image = [ '#theme' => 'image', - '#uri' =>'/core/misc/icons/e32700/error.svg' , + '#uri' => '/core/misc/icons/e32700/error.svg', ]; $message = t('Unable to locate executable at @path', ['@path' => $path]); } @@ -637,14 +634,14 @@ function islandora_directory_exists_message($path) { if ($available) { $image = [ '#theme' => 'image', - '#uri' =>'/core/misc/icons/73b355/check.svg' , + '#uri' => '/core/misc/icons/73b355/check.svg', ]; $message = t('Directory found at @path', ['@path' => $path]); } else { $image = [ '#theme' => 'image', - '#uri' =>'/core/misc/icons/e32700/error.svg' , + '#uri' => '/core/misc/icons/e32700/error.svg', ]; $message = t('Unable to locate directory at @path', ['@path' => $path]); } @@ -766,11 +763,13 @@ function islandora_content_model_select_table_form_element($drupal_variable, arr } // @FIXME -// // @FIXME -// // The correct configuration object could not be determined. You'll need to -// // rewrite this call manually. -// $selected = array_values(variable_get($drupal_variable, $default_values_array)); - + // @FIXME + // The correct configuration object could not be determined. You'll need to + // rewrite this call manually. + // @codingStandardsIgnoreStart + // XXX Commenting out the line below is throwing errors in the code block because $selected + // is undefined. + // $selected = array_values(variable_get($drupal_variable, $default_values_array)); $comparator = function ($a, $b) use ($selected) { $a_val = $b_val = 0; if (in_array($a, $selected)) { @@ -789,6 +788,7 @@ function islandora_content_model_select_table_form_element($drupal_variable, arr ]; $defaults[$pid] = in_array($pid, $selected); } + // @codingStandardsIgnoreEnd $header = [ 'pid' => ['data' => t('PID')], 'title' => ['data' => t('Content Model')], diff --git a/islandora.info.yml b/islandora.info.yml index d7e80657a..0175082fc 100644 --- a/islandora.info.yml +++ b/islandora.info.yml @@ -2,8 +2,8 @@ name: Islandora description: 'View and manage Fedora objects' package: Islandora dependencies: - - image - - file + - drupal:image + - drupal:file core: 8.x php: '5.5.9' type: module diff --git a/islandora.module b/islandora.module index 1c73566e9..721ac8757 100644 --- a/islandora.module +++ b/islandora.module @@ -8,52 +8,54 @@ use Drupal\islandora\DublinCore; use Drupal\islandora\Authentication\Provider\IslandoraTokenAuth; +// @codingStandardsIgnoreStart // Common datastreams. -define('ISLANDORA_DS_COMP_STREAM', 'DS-COMPOSITE-MODEL'); +const ISLANDORA_DS_COMP_STREAM = 'DS-COMPOSITE-MODEL'; // Permissions. -define('ISLANDORA_VIEW_OBJECTS', 'view fedora repository objects'); -define('ISLANDORA_METADATA_EDIT', 'edit fedora metadata'); -define('ISLANDORA_ADD_DS', 'add fedora datastreams'); -define('ISLANDORA_INGEST', 'ingest fedora objects'); +const ISLANDORA_VIEW_OBJECTS = 'view fedora repository objects'; +const ISLANDORA_METADATA_EDIT = 'edit fedora metadata'; +const ISLANDORA_ADD_DS = 'add fedora datastreams'; +const ISLANDORA_INGEST = 'ingest fedora objects'; const ISLANDORA_PURGE = 'delete fedora objects and datastreams'; -define('ISLANDORA_MANAGE_PROPERTIES', 'manage object properties'); -define('ISLANDORA_VIEW_DATASTREAM_HISTORY', 'view old datastream versions'); -define('ISLANDORA_MANAGE_DELETED_OBJECTS', 'manage deleted objects'); -define('ISLANDORA_REVERT_DATASTREAM', 'revert to old datastream'); -define('ISLANDORA_REGENERATE_DERIVATIVES', 'regenerate derivatives for an object'); -define('ISLANDORA_REPLACE_DATASTREAM_CONTENT', 'replace a datastream with new content, preserving version history'); +const ISLANDORA_MANAGE_PROPERTIES = 'manage object properties'; +const ISLANDORA_VIEW_DATASTREAM_HISTORY = 'view old datastream versions'; +const ISLANDORA_MANAGE_DELETED_OBJECTS = 'manage deleted objects'; +const ISLANDORA_REVERT_DATASTREAM = 'revert to old datastream'; +const ISLANDORA_REGENERATE_DERIVATIVES = 'regenerate derivatives for an object'; +const ISLANDORA_REPLACE_DATASTREAM_CONTENT = 'replace a datastream with new content, preserving version history'; // Hooks. -define('ISLANDORA_VIEW_HOOK', 'islandora_view_object'); -define('ISLANDORA_PRINT_HOOK', 'islandora_view_print_object'); -define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object'); -define('ISLANDORA_OVERVIEW_HOOK', 'islandora_overview_object'); -define('ISLANDORA_PRE_INGEST_HOOK', 'islandora_ingest_pre_ingest'); -define('ISLANDORA_POST_INGEST_HOOK', 'islandora_ingest_post_ingest'); -define('ISLANDORA_PRE_PURGE_OBJECT_HOOK', 'islandora_pre_purge_object'); -define('ISLANDORA_POST_PURGE_OBJECT_HOOK', 'islandora_post_purge_object'); +const ISLANDORA_VIEW_HOOK = 'islandora_view_object'; +const ISLANDORA_PRINT_HOOK = 'islandora_view_print_object'; +const ISLANDORA_EDIT_HOOK = 'islandora_edit_object'; +const ISLANDORA_OVERVIEW_HOOK = 'islandora_overview_object'; +const ISLANDORA_PRE_INGEST_HOOK = 'islandora_ingest_pre_ingest'; +const ISLANDORA_POST_INGEST_HOOK = 'islandora_ingest_post_ingest'; +const ISLANDORA_PRE_PURGE_OBJECT_HOOK = 'islandora_pre_purge_object'; +const ISLANDORA_POST_PURGE_OBJECT_HOOK = 'islandora_post_purge_object'; const ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK = 'islandora_update_related_objects_properties'; -define('ISLANDORA_METADATA_OBJECT_ALTER', 'islandora_metadata_object'); -define('ISLANDORA_METADATA_OBJECT_DESCRIPTION_ALTER', 'islandora_metadata_object_description'); -define('ISLANDORA_BREADCRUMB_FILTER_PREDICATE_HOOK', 'islandora_get_breadcrumb_query_predicates'); -define('ISLANDORA_EDIT_DATASTREAM_REGISTRY_HOOK', 'islandora_edit_datastream_registry'); +const ISLANDORA_METADATA_OBJECT_ALTER = 'islandora_metadata_object'; +const ISLANDORA_METADATA_OBJECT_DESCRIPTION_ALTER = 'islandora_metadata_object_description'; +const ISLANDORA_BREADCRUMB_FILTER_PREDICATE_HOOK = 'islandora_get_breadcrumb_query_predicates'; +const ISLANDORA_EDIT_DATASTREAM_REGISTRY_HOOK = 'islandora_edit_datastream_registry'; // @todo Add Documentation. -define('ISLANDORA_OBJECT_INGESTED_HOOK', 'islandora_object_ingested'); -define('ISLANDORA_OBJECT_MODIFIED_HOOK', 'islandora_object_modified'); -define('ISLANDORA_OBJECT_PURGED_HOOK', 'islandora_object_purged'); -define('ISLANDORA_DATASTREAM_INGESTED_HOOK', 'islandora_datastream_ingested'); -define('ISLANDORA_DATASTREAM_MODIFIED_HOOK', 'islandora_datastream_modified'); -define('ISLANDORA_DATASTREAM_PURGED_HOOK', 'islandora_datastream_purged'); -define('ISLANDORA_INGEST_STEP_HOOK', 'islandora_ingest_steps'); -define('ISLANDORA_DERIVATIVE_CREATION_HOOK', 'islandora_derivative'); +const ISLANDORA_OBJECT_INGESTED_HOOK = 'islandora_object_ingested'; +const ISLANDORA_OBJECT_MODIFIED_HOOK = 'islandora_object_modified'; +const ISLANDORA_OBJECT_PURGED_HOOK = 'islandora_object_purged'; +const ISLANDORA_DATASTREAM_INGESTED_HOOK = 'islandora_datastream_ingested'; +const ISLANDORA_DATASTREAM_MODIFIED_HOOK = 'islandora_datastream_modified'; +const ISLANDORA_DATASTREAM_PURGED_HOOK = 'islandora_datastream_purged'; +const ISLANDORA_INGEST_STEP_HOOK = 'islandora_ingest_steps'; +const ISLANDORA_DERIVATIVE_CREATION_HOOK = 'islandora_derivative'; // Autocomplete paths. -define('ISLANDORA_CONTENT_MODELS_AUTOCOMPLETE', 'islandora/autocomplete/content-models'); -define('ISLANDORA_MIME_TYPES_AUTOCOMPLETE', 'islandora/autocomplete/mime-types'); +const ISLANDORA_CONTENT_MODELS_AUTOCOMPLETE = 'islandora/autocomplete/content-models'; +const ISLANDORA_MIME_TYPES_AUTOCOMPLETE = 'islandora/autocomplete/mime-types'; const ISLANDORA_BREADCRUMB_LEGACY_BACKEND = 'islandora_breadcrumbs_legacy_sparql'; +// @codingStandardsIgnoreEnd /** * Implements hook_theme(). @@ -394,7 +396,7 @@ function islandora_default_islandora_printer_object(AbstractObject $object, $alt try { $dc = $islandora_object['DC']->content; - $dc_object = DublinCore::importFromXMLString($dc); + $dc_object = DublinCore::importFromXmlString($dc); } catch (Exception $e) { drupal_set_message(t('Error retrieving object %s %t', ['%s' => $islandora_object->id, '%t' => $e->getMessage()]), 'error', FALSE); diff --git a/islandora.routing.yml b/islandora.routing.yml index e24bc0ece..cf8dcbcba 100644 --- a/islandora.routing.yml +++ b/islandora.routing.yml @@ -30,7 +30,7 @@ islandora.solution_packs_admin_form: path: '/admin/config/islandora/solution_pack_config/solution_packs' defaults: _title: 'Solution packs required objects' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_solution_packs_admin' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraSolutionPacksAdmin' requirements: _permission: 'add fedora datastreams' islandora.tools_admin: @@ -44,22 +44,22 @@ islandora.view_default_object: path: '/islandora' defaults: _title: 'Islandora Repository' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_view_default_object' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraViewDefaultObject' requirements: _permission: 'view fedora repository objects' islandora.view_default_object_0: path: '/islandora/object' defaults: _title: 'Object Browsing' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_view_default_object' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraViewDefaultObject' requirements: _permission: 'view fedora repository objects' islandora.view_object: path: '/islandora/object/{object}' defaults: perms: 'view fedora repository objects' - _title_callback: '\Drupal\islandora\Controller\DefaultController::islandora_drupal_title' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_view_object' + _title_callback: '\Drupal\islandora\Controller\DefaultController::islandoraDrupalTitle' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraViewObject' requirements: _islandora_object_access: 'TRUE' options: @@ -71,9 +71,9 @@ islandora.printer_object: defaults: op: 'view fedora repository objects' _title: 'Print Object' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_printer_object' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraPrintObject' requirements: - _custom_access: '\Drupal\islandora\Controller\DefaultController::islandora_print_object_access' + _custom_access: '\Drupal\islandora\Controller\DefaultController::islandoraPrintObjectAccess' options: parameters: object: @@ -83,9 +83,9 @@ islandora.print_object: defaults: op: 'view fedora repository objects' _title: 'Print Object' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_print_object' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraPrintObject' requirements: - _custom_access: '\Drupal\islandora\Controller\DefaultController::islandora_print_object_access' + _custom_access: '\Drupal\islandora\Controller\DefaultController::islandoraPrintObjectAccess' options: parameters: object: @@ -179,11 +179,11 @@ islandora.add_datastream_form_autocomplete_callback: path: '/islandora/object/{object}/manage/datastreams/add/autocomplete' defaults: perm: 'add fedora datastreams' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_add_datastream_form_autocomplete_callback' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraAddDatastreamFormAutocompleteCallback' options: _admin_route: TRUE requirements: - _custom_access: '\Drupal\islandora\Controller\DefaultController::islandora_object_access_callback' + _custom_access: '\Drupal\islandora\Controller\DefaultController::islandoraObjectAccessCallback' islandora.view_datastream: path: '/islandora/object/{object}/datastream/{datastream}' defaults: @@ -233,7 +233,7 @@ islandora.edit_datastream: defaults: perms: 'edit fedora metadata' _title: 'Edit datastream' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_edit_datastream' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraEditDatastream' requirements: _islandora_datastream_access: 'TRUE' options: @@ -263,7 +263,7 @@ islandora.datastream_version_table: defaults: perms: 'view old datastream versions' _title: 'Datastream Versions' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_datastream_version_table' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraDatastreamVersionTable' requirements: _islandora_datastream_access: 'TRUE' options: @@ -351,7 +351,7 @@ islandora.event_status: path: '/islandora/event-status' defaults: _title: 'Event Status' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_event_status' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraEventStatus' requirements: # No access restriction due to D7 legacy. _access: 'TRUE' @@ -359,14 +359,14 @@ islandora.content_model_autocomplete: path: '/islandora/autocomplete/content-models' defaults: _title: 'Autocomplete callback' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_content_model_autocomplete' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraContentModelAutocomplete' requirements: _permission: 'administer site configuration' islandora.mime_type_autocomplete: path: '/islandora/autocomplete/mime-types' defaults: _title: 'Autocomplete callback' - _controller: '\Drupal\islandora\Controller\DefaultController::islandora_mime_type_autocomplete' + _controller: '\Drupal\islandora\Controller\DefaultController::islandoraMimeTypeAutocomplete' requirements: _permission: 'administer site configuration' islandora.deleted_objects_manage_form: diff --git a/islandora.services.yml b/islandora.services.yml index e1f1526c0..b12bd0276 100644 --- a/islandora.services.yml +++ b/islandora.services.yml @@ -1,6 +1,7 @@ services: object: class: Drupal\islandora\ParamConverter\IslandoraObjectParamConverter + arguments: ['@config.factory'] tags: - { name: paramconverter } access_check.object: diff --git a/js/spin/spin.min.js b/js/spin/spin.min.js index d42839198..d79481331 100644 --- a/js/spin/spin.min.js +++ b/js/spin/spin.min.js @@ -1 +1,3 @@ -(function(t,e){if(typeof exports=="object")module.exports=e();else if(typeof define=="function"&&define.amd)define(e);else t.Spinner=e()})(this,function(){"use strict";var t=["webkit","Moz","ms","O"],e={},i;function o(t,e){var i=document.createElement(t||"div"),o;for(o in e)i[o]=e[o];return i}function n(t){for(var e=1,i=arguments.length;e>1):parseInt(n.left,10)+s)+"px",top:(n.top=="auto"?l.y-a.y+(t.offsetHeight>>1):parseInt(n.top,10)+s)+"px"})}r.setAttribute("role","progressbar");e.lines(r,e.opts);if(!i){var d=0,p=(n.lines-1)*(1-n.direction)/2,c,h=n.fps,m=h/n.speed,y=(1-n.opacity)/(m*n.trail/100),g=m/n.lines;(function v(){d++;for(var t=0;t>1)+"px"})}for(;r',e)}r.addRule(".spin-vml","behavior:url(#default#VML)");c.prototype.lines=function(e,i){var o=i.length+i.width,r=2*o;function s(){return f(t("group",{coordsize:r+" "+r,coordorigin:-o+" "+-o}),{width:r,height:r})}var a=-(i.width+i.length)*2+"px",l=f(s(),{position:"absolute",top:a,left:a}),u;function p(e,r,a){n(l,n(f(s(),{rotation:360/i.lines*e+"deg",left:~~r}),n(f(t("roundrect",{arcsize:i.corners}),{width:o,height:i.width,left:i.radius,top:-i.width>>1,filter:a}),t("fill",{color:d(i.color,e),opacity:i.opacity}),t("stroke",{opacity:0}))))}if(i.shadow)for(u=1;u<=i.lines;u++)p(u,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(u=1;u<=i.lines;u++)p(u);return n(e,l)};c.prototype.opacity=function(t,e,i,o){var n=t.firstChild;o=o.shadow&&o.lines||0;if(n&&e+o>1):parseInt(n.left,10)+s)+"px",top:(n.top=="auto"?l.y-a.y+(t.offsetHeight>>1):parseInt(n.top,10)+s)+"px"})}r.setAttribute("role","progressbar");e.lines(r,e.opts);if(!i){var d=0,p=(n.lines-1)*(1-n.direction)/2,c,h=n.fps,m=h/n.speed,y=(1-n.opacity)/(m*n.trail/100),g=m/n.lines;(function v(){d++;for(var t=0;t>1)+"px"})}for(;r',e)}r.addRule(".spin-vml","behavior:url(#default#VML)");c.prototype.lines=function(e,i){var o=i.length+i.width,r=2*o;function s(){return f(t("group",{coordsize:r+" "+r,coordorigin:-o+" "+-o}),{width:r,height:r})}var a=-(i.width+i.length)*2+"px",l=f(s(),{position:"absolute",top:a,left:a}),u;function p(e,r,a){n(l,n(f(s(),{rotation:360/i.lines*e+"deg",left:~~r}),n(f(t("roundrect",{arcsize:i.corners}),{width:o,height:i.width,left:i.radius,top:-i.width>>1,filter:a}),t("fill",{color:d(i.color,e),opacity:i.opacity}),t("stroke",{opacity:0}))))}if(i.shadow)for(u=1;u<=i.lines;u++)p(u,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(u=1;u<=i.lines;u++)p(u);return n(e,l)};c.prototype.opacity=function(t,e,i,o){var n=t.firstChild;o=o.shadow&&o.lines||0;if(n&&e+oconfig = $config; - } - - /** - * Dependency injection interface. - */ - public static function create(ConfigFactoryInterface $config) { - return new static($config); + public function __construct(ConfigFactoryInterface $configFactory) { + $this->configFactory = $configFactory; } /** @@ -57,7 +50,7 @@ public function access($perms, $object, AccountInterface $account, $islandora_ac // around this by making the empty slug route in YAML or a custom Routing // object we can remove this. $object = islandora_object_load($object === 'root' ? - $this->config->get('islandora.settings')->get('islandora_repository_pid') : + $this->configFactory->get('islandora.settings')->get('islandora_repository_pid') : $object); if (!$object && !islandora_describe_repository()) { islandora_display_repository_inaccessible_message(); diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 7ca63d4fb..2039b736b 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -5,8 +5,8 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Url; +use Drupal\Core\Render\Renderer; use Drupal\islandora\Form\IslandoraSolutionPackForm; @@ -27,13 +27,16 @@ */ class DefaultController extends ControllerBase { - protected $formbuilder; + protected $renderer; + + protected $appRoot; /** * Constructor for dependency injection. */ - public function __construct(FormBuilderInterface $formbuilder) { - $this->formbuilder = $formbuilder; + public function __construct(Renderer $renderer, $appRoot) { + $this->renderer = $renderer; + $this->appRoot = $appRoot; } /** @@ -41,7 +44,8 @@ public function __construct(FormBuilderInterface $formbuilder) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('form_builder') + $container->get('renderer'), + $container->get('app.root') ); } @@ -53,7 +57,7 @@ public static function create(ContainerInterface $container) { * * @throws \Exception */ - public function islandora_solution_packs_admin() { + public function islandoraSolutionPacksAdmin() { module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/solution_packs'); @@ -71,7 +75,7 @@ public function islandora_solution_packs_admin() { $objects = array_filter($solution_pack_info['objects']); $class_name = IslandoraSolutionPackForm::class; - $output[$solution_pack_module] = $this->formbuilder->getForm($class_name, $solution_pack_module, $solution_pack_name, $objects); + $output[$solution_pack_module] = $this->formBuilder()->getForm($class_name, $solution_pack_module, $solution_pack_name, $objects); } return $output; @@ -83,21 +87,24 @@ public function islandora_solution_packs_admin() { * Redirects to the view of the object indicated by the Drupal variable * 'islandora_repository_pid'. */ - public function islandora_view_default_object() { - $pid = \Drupal::config('islandora.settings')->get('islandora_repository_pid'); + public function islandoraViewDefaultObject() { + $pid = $this->config('islandora.settings')->get('islandora_repository_pid'); return $this->redirect('islandora.view_object', ['object' => $pid]); } /** * Title callback for Drupal title to be the object label. */ - public function islandora_drupal_title(AbstractObject $object) { + public function islandoraDrupalTitle(AbstractObject $object) { module_load_include('inc', 'islandora', 'includes/breadcrumb'); - //drupal_set_breadcrumb(islandora_get_breadcrumbs($object)); + // drupal_set_breadcrumb(islandora_get_breadcrumbs($object)); return $object->label; } - public function islandora_object_access_callback($perm, $object, AccountInterface $account) { + /** + * Access callback for Drupal object. + */ + public function islandoraObjectAccessCallback($perm, $object, AccountInterface $account) { module_load_include('inc', 'islandora', 'includes/utilities'); if (!$object && !islandora_describe_repository()) { islandora_display_repository_inaccessible_message(); @@ -106,19 +113,22 @@ public function islandora_object_access_callback($perm, $object, AccountInterfac return AccessResult::allowedIf(islandora_object_access($perm, $object, $account)); } - public function islandora_view_object(AbstractObject $object) { + /** + * View islandora object. + */ + public function islandoraViewObject(AbstractObject $object, Request $currentRequest) { module_load_include('inc', 'islandora', 'includes/breadcrumb'); module_load_include('inc', 'islandora', 'includes/utilities'); // XXX: This seems so very dumb but given how empty slugs don't play nice // in Drupal as defaults this needs to be the case. If it's possible to get // around this by making the empty slug route in YAML or a custom Routing // object we can remove this. - if (\Drupal::request()->getRequestUri() === '/islandora/object/') { - return $this->redirect('islandora.view_object', ['object' => \Drupal::config('islandora.settings')->get('islandora_repository_pid')]); + if ($currentRequest->getRequestUri() === '/islandora/object/') { + return $this->redirect('islandora.view_object', ['object' => $this->config('islandora.settings')->get('islandora_repository_pid')]); } // Warn if object is inactive or deleted. if ($object->state != 'A') { - drupal_set_message(t('This object is not active. Metadata may not display correctly.'), 'warning'); + drupal_set_message($this->t('This object is not active. Metadata may not display correctly.'), 'warning'); } // Optional pager parameters. $page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; @@ -128,7 +138,7 @@ public function islandora_view_object(AbstractObject $object) { foreach ($hooks as $hook) { // @todo Remove page number and size from this hook, implementers of the // hook should use drupal page handling directly. - $temp = \Drupal::moduleHandler()->invokeAll($hook, [ + $temp = $this->moduleHandler()->invokeAll($hook, [ $object, $page_number, $page_size, @@ -143,30 +153,33 @@ public function islandora_view_object(AbstractObject $object) { } arsort($output); - \Drupal::moduleHandler()->alter($hooks, $object, $output); + $this->moduleHandler()->alter($hooks, $object, $output); return $output; } /** * Access callback for printing an object. */ - public function islandora_print_object_access($op, $object, AccountInterface $account) { + public function islandoraPrintObjectAccess($op, $object, AccountInterface $account) { $object = islandora_object_load($object); return AccessResult::allowedIf(islandora_print_object_access($op, $object, $account)); } - public static function islandora_printer_object(AbstractObject $object) { + /** + * Islandora printer object. + */ + public static function islandoraPrinterObject(AbstractObject $object) { $output = []; $temp_arr = []; // Dispatch print hook. foreach (islandora_build_hook_list(ISLANDORA_PRINT_HOOK, $object->models) as $hook) { - $temp = \Drupal::moduleHandler()->invokeAll($hook, [$object]); + $temp = $this->moduleHandler()->invokeAll($hook, [$object]); if (!empty($temp)) { $temp_arr = array_merge_recursive($temp_arr, $temp); } } - $output = islandora_default_islandora_printer_object($object, \Drupal::service("renderer")->render($temp_arr)); + $output = islandora_default_islandora_printer_object($object, $this->renderer->render($temp_arr)); arsort($output); // Prompt to print. @@ -174,7 +187,10 @@ public static function islandora_printer_object(AbstractObject $object) { return $output; } - public function islandora_object_access($op, $object, $user = NULL, AccountInterface $account) { + /** + * Islandora object access. + */ + public function islandoraObjectAccess($op, $object, AccountInterface $user = NULL) { $cache = &drupal_static(__FUNCTION__); if (!is_object($object)) { // The object could not be loaded... Presumably, we don't have @@ -182,7 +198,7 @@ public function islandora_object_access($op, $object, $user = NULL, AccountInter return FALSE; } if ($user === NULL) { - $user = \Drupal::currentUser(); + $user = $this->currentUser(); } // Populate the cache on a miss. @@ -207,21 +223,24 @@ public function islandora_object_access($op, $object, $user = NULL, AccountInter * the 'content' variable, or override the display by providing a theme * suggestion. * - * @param AbstractObject $object + * @param \AbstractObject $object * The object. * * @return array * A renderable array. */ - public function islandora_print_object(AbstractObject $object) { - return [ - '#title' => $object->label, - '#theme' => 'islandora_object_print', - '#object' => $object, - ]; + public function islandoraPrintObject(AbstractObject $object) { + return [ + '#title' => $object->label, + '#theme' => 'islandora_object_print', + '#object' => $object, + ]; } - public function islandora_object_manage_access_callback($perms, $object = NULL, AccountInterface $account) { + /** + * Object management access callback. + */ + public function islandoraObjectManageAccessCallback($perms, $object = NULL, AccountInterface $account = NULL) { module_load_include('inc', 'islandora', 'includes/utilities'); if (!$object && !islandora_describe_repository()) { @@ -231,7 +250,7 @@ public function islandora_object_manage_access_callback($perms, $object = NULL, $has_access = FALSE; for ($i = 0; $i < count($perms) && !$has_access; $i++) { - $has_access = $has_access || islandora_object_access($perms[$i], $object); + $has_access = $has_access || islandora_object_access($perms[$i], $object, $account); } return $has_access; @@ -242,14 +261,14 @@ public function islandora_object_manage_access_callback($perms, $object = NULL, * * It lists the missing required (may be optional) datastreams. */ - public function islandora_add_datastream_form_autocomplete_callback(AbstractObject $object, Request $request) { + public function islandoraAddDatastreamFormAutocompleteCallback(AbstractObject $object, Request $request) { module_load_include('inc', 'islandora', 'includes/content_model'); module_load_include('inc', 'islandora', 'includes/utilities'); $query = $request->query->get('q'); $dsids = array_keys(islandora_get_missing_datastreams_requirements($object)); $query = trim($query); if (!empty($query)) { - $filter = function($id) use($query) { + $filter = function ($id) use ($query) { return stripos($id, $query) !== FALSE; }; $dsids = array_filter($dsids, $filter); @@ -369,7 +388,7 @@ public function islandoraDownloadDatastream(AbstractDatastream $datastream) { /** * Page callback for editing a datastream. */ - public function islandora_edit_datastream(AbstractDatastream $datastream) { + public function islandoraEditDatastream(AbstractDatastream $datastream) { module_load_include('inc', 'islandora', 'includes/utilities'); $edit_registry = islandora_build_datastream_edit_registry($datastream); @@ -408,7 +427,7 @@ public function islandora_edit_datastream(AbstractDatastream $datastream) { /** * Page callback for the datastream version table. */ - public function islandora_datastream_version_table(AbstractDatastream $datastream) { + public function islandoraDatastreamVersionTable(AbstractDatastream $datastream) { module_load_include('inc', 'islandora', 'includes/datastream.version'); return islandora_datastream_version_table($datastream); } @@ -416,7 +435,7 @@ public function islandora_datastream_version_table(AbstractDatastream $datastrea /** * Page callback for session status messages. */ - public function islandora_event_status() { + public function islandoraEventStatus() { $results = FALSE; if (isset($_SESSION['islandora_event_messages'])) { foreach ($_SESSION['islandora_event_messages'] as $message) { @@ -432,7 +451,7 @@ public function islandora_event_status() { /** * Autocomplete the content model name. */ - public function islandora_content_model_autocomplete(Request $request) { + public function islandoraContentModelAutocomplete(Request $request) { module_load_include('inc', 'islandora', 'includes/content_model.autocomplete'); $string = $request->query->get('q'); $content_models = islandora_get_content_model_names(); @@ -448,17 +467,8 @@ public function islandora_content_model_autocomplete(Request $request) { /** * Autocomplete the MIME type name. */ - public function islandora_mime_type_autocomplete(Request $request) { - require_once \Drupal::root() . "/includes/file.mimetypes.inc"; - $string = $request->query->get('q'); - $mime_types = file_mimetype_mapping(); - $output = []; - foreach ($mime_types as $mime_type) { - if (preg_match("/{$string}/i", $mime_type) !== 0) { - $output[] = ['value' => $mime_type, 'label' => $mime_type]; - } - } - return new JsonResponse($output); + public function islandoraMimeTypeAutocomplete(Request $request) { + throw new Exception('Not implemented.'); } } diff --git a/src/DublinCore.php b/src/DublinCore.php index 00cbcaaac..43bca8daf 100644 --- a/src/DublinCore.php +++ b/src/DublinCore.php @@ -39,7 +39,7 @@ class DublinCore { */ public function __construct($dc_xml = NULL) { if (!empty($dc_xml)) { - $this->dc = self::importFromXMLString($dc_xml); + $this->dc = self::importFromXmlString($dc_xml); } } @@ -80,7 +80,7 @@ public function setElement($element_name, $values) { * @return string * The serialized XML. */ - public function asXML() { + public function asXml() { $dc_xml = new DomDocument(); $oai_dc = $dc_xml->createElementNS('http://www.openarchives.org/OAI/2.0/oai_dc/', 'oai_dc:dc'); $oai_dc->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); @@ -151,7 +151,7 @@ public function asArray() { * @return DublinCore * The instantiated object. */ - public static function importFromXMLString($dc_xml) { + public static function importFromXmlString($dc_xml) { $dc_doc = new \DOMDocument(); if (!empty($dc_xml) && $dc_doc->loadXML($dc_xml)) { $oai_dc = $dc_doc->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', '*'); diff --git a/src/Form/IslandoraIngestForm.php b/src/Form/IslandoraIngestForm.php index 1f5a5773d..8b5f3ae50 100644 --- a/src/Form/IslandoraIngestForm.php +++ b/src/Form/IslandoraIngestForm.php @@ -58,7 +58,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $configur drupal_set_message($e->getMessage(), 'error'); return [ [ - '#markup' => \Drupal::l($this->t('Back'), Url::fromUri('javascript:window.history.back();')), + '#markup' => $this->getLinkGenerator()->generate($this->t('Back'), Url::fromUri('javascript:window.history.back();')), ], ]; } diff --git a/src/ParamConverter/IslandoraObjectParamConverter.php b/src/ParamConverter/IslandoraObjectParamConverter.php index 530280f78..f1e79c479 100644 --- a/src/ParamConverter/IslandoraObjectParamConverter.php +++ b/src/ParamConverter/IslandoraObjectParamConverter.php @@ -3,6 +3,8 @@ namespace Drupal\islandora\ParamConverter; use Drupal\Core\ParamConverter\ParamConverterInterface; +use Drupal\Core\Config\ConfigFactoryInterface; + use Symfony\Component\Routing\Route; /** @@ -10,6 +12,15 @@ */ class IslandoraObjectParamConverter implements ParamConverterInterface { + private $config; + + /** + * {@inheritdoc} + */ + public function __construct(ConfigFactoryInterface $configFactory) { + $this->config = $configFactory->get('islandora.settings'); + } + /** * Object parameter converter method. */ @@ -18,7 +29,7 @@ public function convert($value, $definition, $name, array $defaults) { // in Drupal as defaults this needs to be the case. If it's possible to get // around this by making the empty slug route in YAML or a custom Routing // object we can remove this. - $value = $value === 'root' ? \Drupal::config('islandora.settings')->get('islandora_repository_pid') : $value; + $value = $value === 'root' ? $this->config->get('islandora_repository_pid') : $value; return islandora_object_load($value); } diff --git a/src/Plugin/Block/AbstractConfiguredBlockBase.php b/src/Plugin/Block/AbstractConfiguredBlockBase.php new file mode 100644 index 000000000..03583d1ae --- /dev/null +++ b/src/Plugin/Block/AbstractConfiguredBlockBase.php @@ -0,0 +1,37 @@ +get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $configFactory) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->configFactory = $configFactory; + } + +} diff --git a/src/Plugin/Block/AbstractFormBlockBase.php b/src/Plugin/Block/AbstractFormBlockBase.php new file mode 100644 index 000000000..8a0b8e24b --- /dev/null +++ b/src/Plugin/Block/AbstractFormBlockBase.php @@ -0,0 +1,38 @@ +get('form_builder') + ); + } + + /** + * {@inheritdoc} + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilderInterface $formBuilder) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->formBuilder = $formBuilder; + } + +} diff --git a/src/Tuque/IslandoraFedoraRepository.php b/src/Tuque/IslandoraFedoraRepository.php index fb1d0af09..f106b19b6 100644 --- a/src/Tuque/IslandoraFedoraRepository.php +++ b/src/Tuque/IslandoraFedoraRepository.php @@ -74,7 +74,7 @@ public function ingestObject(NewFedoraObject &$object) { public function constructObject($id = NULL, $create_uuid = NULL) { // Enforces UUID when set, but allows to override if called // with $create_uuid set to bool. - return parent::constructObject($id, static::useUUIDs($create_uuid)); + return parent::constructObject($id, static::useUuids($create_uuid)); } /** @@ -85,7 +85,7 @@ public function constructObject($id = NULL, $create_uuid = NULL) { public function getNextIdentifier($namespace = NULL, $create_uuid = NULL, $count = 1) { // Enforces UUID when set, but allows to override if called // with $create_uuid set to bool. - return parent::getNextIdentifier($namespace, static::useUUIDs($create_uuid), $count); + return parent::getNextIdentifier($namespace, static::useUuids($create_uuid), $count); } /** @@ -99,7 +99,7 @@ public function getNextIdentifier($namespace = NULL, $create_uuid = NULL, $count * 'islandora_basic_collection_generate_uuid' Drupal variable; otherwise, * the value of $to_create itself. */ - protected static function useUUIDs($to_create) { + protected static function useUuids($to_create) { return is_null($to_create) ? \Drupal::config('islandora.settings')->get('islandora_basic_collection_generate_uuid') : $to_create; diff --git a/theme/theme.inc b/theme/theme.inc index c69547a74..1fe6a32e2 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -45,7 +45,7 @@ function template_preprocess_islandora_default(&$variables) { $variables['datastreams'] = $datastreams; // Objects in fcrepo4 don't always contain a DC datastream. if (isset($islandora_object['DC']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) { - $dc_object = DublinCore::importFromXMLString($islandora_object['DC']->content); + $dc_object = DublinCore::importFromXmlString($islandora_object['DC']->content); $dc_array = $dc_object->asArray(); } // We should eventually remove the DC object and dc_array code as it only @@ -149,7 +149,7 @@ function islandora_objects_object_mapper($object_id) { if ($object) { $description = NULL; if (isset($object['DC']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $object['DC'])) { - $dc = DublinCore::importFromXMLString($object['DC']->content); + $dc = DublinCore::importFromXmlString($object['DC']->content); if ($dc) { $dc = $dc->asArray(); $description = $dc['dc:description']['value']; @@ -256,7 +256,7 @@ function template_preprocess_islandora_dublin_core_display(array &$variables) { if (islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) { try { $dc = $islandora_object['DC']->content; - $dc_object = DublinCore::importFromXMLString($dc); + $dc_object = DublinCore::importFromXmlString($dc); } catch (Exception $e) { drupal_set_message(t('Error retrieving object %s %t', ['%s' => $islandora_object->id, '%t' => $e->getMessage()]), 'error', FALSE); @@ -273,7 +273,7 @@ function template_preprocess_islandora_dublin_core_description(array &$variables if (islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) { try { $dc = $islandora_object['DC']->content; - $dc_object = DublinCore::importFromXMLString($dc); + $dc_object = DublinCore::importFromXmlString($dc); } catch (Exception $e) { drupal_set_message(t('Error retrieving object %s %t', ['%s' => $islandora_object->id, '%t' => $e->getMessage()]), 'error', FALSE);