diff --git a/includes/handlers/shs_handler_filter_entityreference.inc b/includes/handlers/shs_handler_filter_entityreference.inc index 7c23a80..366ca14 100644 --- a/includes/handlers/shs_handler_filter_entityreference.inc +++ b/includes/handlers/shs_handler_filter_entityreference.inc @@ -16,8 +16,8 @@ class shs_handler_filter_entityreference extends views_handler_filter_numeric { function option_definition() { $options = parent::option_definition(); - $options['shs_enabled'] = array('default' => FALSE); - $options['use_chosen'] = array('default' => 'never'); + $options['shs_enabled'] = ['default' => FALSE]; + $options['use_chosen'] = ['default' => 'never']; return $options; } @@ -33,27 +33,27 @@ class shs_handler_filter_entityreference extends views_handler_filter_numeric { function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); - $form['shs_enabled'] = array( + $form['shs_enabled'] = [ '#type' => 'checkbox', '#title' => t('Output filter as hierarchical select'), '#default_value' => $this->options['shs_enabled'], - ); + ]; if (module_exists('chosen')) { - $form['use_chosen'] = array( + $form['use_chosen'] = [ '#type' => 'select', - '#title' => t('Output this field with !chosen', array('!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen'))), - '#description' => t('Select in which cases the element will use the !chosen module for the term selection of each level.', array('!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen'))), + '#title' => t('Output this field with !chosen', ['!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen')]), + '#description' => t('Select in which cases the element will use the !chosen module for the term selection of each level.', ['!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen')]), '#default_value' => empty($this->options['use_chosen']) ? 'never' : $this->options['use_chosen'], - '#dependency' => array( - 'edit-options-shs-enabled' => array(1), - ), - '#options' => array( + '#dependency' => [ + 'edit-options-shs-enabled' => [1], + ], + '#options' => [ 'chosen' => t('let chosen decide'), 'always' => t('always'), 'never' => t('never'), - ), - ); + ], + ]; } } @@ -74,16 +74,16 @@ class shs_handler_filter_entityreference extends views_handler_filter_numeric { $field = field_info_field($this->definition['field_name']); $handler = entityreference_get_selection_handler($field); $referencable_entities = $handler->getReferencableEntities(); - $vocabulary_names = array(); + $vocabulary_names = []; if ('views' === $field['settings']['handler']) { $view_settings = $field['settings']['handler_settings']['view']; // Try to load vocabularies from view filter. $vocabulary_names = _shs_entityreference_views_get_vocabularies($view_settings['view_name'], $view_settings['display_name']); } else { - $vocabulary_names = empty($field['settings']['handler_settings']['target_bundles']) ? array() : $field['settings']['handler_settings']['target_bundles']; + $vocabulary_names = empty($field['settings']['handler_settings']['target_bundles']) ? [] : $field['settings']['handler_settings']['target_bundles']; } - $vocabularies = array(); + $vocabularies = []; foreach ($vocabulary_names as $vocabulary_name) { if (($vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_name)) !== FALSE) { $vocabularies[] = $vocabulary; @@ -101,7 +101,7 @@ class shs_handler_filter_entityreference extends views_handler_filter_numeric { } } - $parents = array(); + $parents = []; if (!empty($default_value) && $default_value != 'All') { if (is_array($default_value) && $default_value[0] != 'All') { foreach ($default_value as $delta => $level) { @@ -113,22 +113,22 @@ class shs_handler_filter_entityreference extends views_handler_filter_numeric { // Remove selected term from list. array_shift($term_parents); foreach (array_reverse($term_parents) as $term) { - $parents[] = array('tid' => $term->tid); + $parents[] = ['tid' => $term->tid]; } // Add current term (name not needed). - $parents[] = array('tid' => $default_value); + $parents[] = ['tid' => $default_value]; } } // Add fake item for next level. - $parents[] = array('tid' => 0); + $parents[] = ['tid' => 0]; - $element_settings = array( + $element_settings = [ 'create_new_terms' => FALSE, 'create_new_levels' => FALSE, 'required' => FALSE, 'language' => $language, - ); + ]; if (module_exists('chosen') && !empty($this->options['use_chosen'])) { $element_settings['use_chosen'] = $this->options['use_chosen']; } @@ -140,9 +140,9 @@ class shs_handler_filter_entityreference extends views_handler_filter_numeric { $element_settings = array_merge($element_settings, $this->options['expose']['shs']); } - $vocabulary_identifier = array( + $vocabulary_identifier = [ 'field_name' => $field['field_name'], - ); + ]; if (count($vocabularies) == 1) { // Get ID from first (and only) vocabulary. $vocabulary_identifier = $vocabularies[0]->vid; @@ -152,10 +152,10 @@ class shs_handler_filter_entityreference extends views_handler_filter_numeric { // This is necessary until http://drupal.org/node/208611 lands for D7. $js_hash = _shs_create_hash(); // Create settings needed for our js magic. - $settings_js = array( - 'shs' => array( - $identifier => array( - $js_hash => array( + $settings_js = [ + 'shs' => [ + $identifier => [ + $js_hash => [ 'vid' => $vocabulary_identifier, 'settings' => $element_settings, 'default_value' => $default_value, @@ -163,10 +163,10 @@ class shs_handler_filter_entityreference extends views_handler_filter_numeric { 'multiple' => $multiple, 'any_label' => variable_get('views_exposed_filter_any_label', 'new_any') == 'old_any' ? t('') : t('- Any -'), 'any_value' => 'All', - ), - ), - ), - ); + ], + ], + ], + ]; // Add settings. drupal_add_js($settings_js, 'setting'); // Add behavior. @@ -183,7 +183,7 @@ class shs_handler_filter_entityreference extends views_handler_filter_numeric { } } - $options = array(); + $options = []; foreach ($referencable_entities as $terms) { $options += $terms; } @@ -192,9 +192,11 @@ class shs_handler_filter_entityreference extends views_handler_filter_numeric { $form['value']['#options'] = $options; $form['value']['#size'] = 1; $form['value']['#default_value'] = empty($default_value) ? 'All' : $default_value; - $form['value']['#attributes'] = array( - 'class' => array('element-invisible', 'shs-enabled'), - ); + $form['value']['#attributes'] = [ + 'class' => ['element-invisible', 'shs-enabled'], + ]; + $form['#js_callback'] = ['shs' => 'json']; + if (!empty($form_state['exposed']) && isset($identifier) && empty($form_state['input'][$identifier]) || $multiple && isset($form_state['input'][$identifier][0])) { $form_state['input'][$identifier] = empty($default_value_str) ? 'All' : $default_value_str; diff --git a/includes/handlers/shs_handler_filter_term_node_tid.inc b/includes/handlers/shs_handler_filter_term_node_tid.inc index 8d32f3b..eab0a82 100644 --- a/includes/handlers/shs_handler_filter_term_node_tid.inc +++ b/includes/handlers/shs_handler_filter_term_node_tid.inc @@ -15,8 +15,8 @@ class shs_handler_filter_term_node_tid extends views_handler_filter_term_node_ti function option_definition() { $options = parent::option_definition(); - $options['type'] = array('default' => 'shs'); - $options['use_chosen'] = array('default' => 'never'); + $options['type'] = ['default' => 'shs']; + $options['use_chosen'] = ['default' => 'never']; return $options; } @@ -24,23 +24,23 @@ class shs_handler_filter_term_node_tid extends views_handler_filter_term_node_ti function extra_options_form(&$form, &$form_state) { parent::extra_options_form($form, $form_state); - $form['type']['#options'] += array( + $form['type']['#options'] += [ 'shs' => t('Simple hierarchical select'), - ); + ]; if (module_exists('chosen')) { - $form['use_chosen'] = array( + $form['use_chosen'] = [ '#type' => 'select', - '#title' => t('Output this field with !chosen', array('!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen'))), - '#description' => t('Select in which cases the element will use the !chosen module for the term selection of each level.', array('!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen'))), + '#title' => t('Output this field with !chosen', ['!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen')]), + '#description' => t('Select in which cases the element will use the !chosen module for the term selection of each level.', ['!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen')]), '#default_value' => empty($this->options['use_chosen']) ? 'never' : $this->options['use_chosen'], - '#dependency' => array('radio:options[type]' => array('shs')), - '#options' => array( + '#dependency' => ['radio:options[type]' => ['shs']], + '#options' => [ 'chosen' => t('let chosen decide'), 'always' => t('always'), 'never' => t('never'), - ), - ); + ], + ]; } } @@ -52,9 +52,9 @@ class shs_handler_filter_term_node_tid extends views_handler_filter_term_node_ti $multiple = $this->options['expose']['multiple']; $vocabulary = taxonomy_vocabulary_machine_name_load($this->options['vocabulary']); if (empty($vocabulary) && $this->options['limit']) { - $form['markup'] = array( + $form['markup'] = [ '#markup' => '
' . t('An invalid vocabulary is selected. Please change it in the options.') . '
', - ); + ]; return; } @@ -67,48 +67,48 @@ class shs_handler_filter_term_node_tid extends views_handler_filter_term_node_ti if (!empty($form_state['input'][$identifier])) { $default_value = $form_state['input'][$identifier]; if ($multiple && !is_array($default_value)) { - $default_value = array($default_value); + $default_value = [$default_value]; } } - $parents = array(); + $parents = []; if (!empty($default_value) && $default_value != 'All') { if (is_array($default_value) && $default_value[0] != 'All') { if (strpos($default_value[0], ',') !== FALSE || strpos($default_value[0], '+') !== FALSE) { - $values = array(); + $values = []; foreach ($default_value as $default) { $values += preg_split('/[,\+]+/', $default, -1, PREG_SPLIT_NO_EMPTY); } $form_state['input'][$identifier] = empty($values) ? 'All' : $values; $default_value = $values; } - $parents_multiple = array(); + $parents_multiple = []; foreach ($default_value as $delta => $tid) { $parents_multiple[] = $tid; } - $parents[] = array('tid' => $parents_multiple); + $parents[] = ['tid' => $parents_multiple]; } elseif (is_string($default_value)) { $term_parents = taxonomy_get_parents_all($default_value); // Remove selected term from list. array_shift($term_parents); foreach (array_reverse($term_parents) as $term) { - $parents[] = array('tid' => $term->tid); + $parents[] = ['tid' => $term->tid]; } // Add current term (name not needed). - $parents[] = array('tid' => $default_value); + $parents[] = ['tid' => $default_value]; } } // Add fake item for next level. - $parents[] = array('tid' => 0); + $parents[] = ['tid' => 0]; - $element_settings = array( + $element_settings = [ 'create_new_terms' => FALSE, 'create_new_levels' => FALSE, 'required' => FALSE, 'language' => $language, - ); + ]; if (module_exists('chosen') && !empty($this->options['use_chosen'])) { $element_settings['use_chosen'] = $this->options['use_chosen']; } @@ -124,10 +124,10 @@ class shs_handler_filter_term_node_tid extends views_handler_filter_term_node_ti // This is necessary until http://drupal.org/node/208611 lands for D7. $js_hash = _shs_create_hash(); // Create settings needed for our js magic. - $settings_js = array( - 'shs' => array( - $identifier . ($multiple ? '[]' : '') => array( - $js_hash => array( + $settings_js = [ + 'shs' => [ + $identifier . ($multiple ? '[]' : '') => [ + $js_hash => [ 'vid' => $vocabulary->vid, 'settings' => $element_settings, 'default_value' => $default_value, @@ -135,22 +135,23 @@ class shs_handler_filter_term_node_tid extends views_handler_filter_term_node_ti 'multiple' => $multiple, 'any_label' => variable_get('views_exposed_filter_any_label', 'new_any') == 'old_any' ? t('') : t('- Any -'), 'any_value' => 'All', - ), - ), - ), - ); - drupal_alter(array('shs_js_settings', "shs_{$identifier}_js_settings"), $settings_js, $identifier, $vocabulary->vid); + ], + ], + ], + ]; + drupal_alter(['shs_js_settings', "shs_{$identifier}_js_settings"], $settings_js, $identifier, $vocabulary->vid); // Add settings. drupal_add_js($settings_js, 'setting'); // Add behavior. drupal_add_js(drupal_get_path('module', 'shs') . '/js/shs.js'); // Rewrite default select element. - $form['value'] += array( - '#attributes' => array( - 'class' => array('element-invisible', 'shs-enabled'), - ), - ); + $form['value'] += [ + '#attributes' => [ + 'class' => ['element-invisible', 'shs-enabled'], + ], + '#js_callback' => ['shs' => 'json'], + ]; } if (empty($form_state['exposed'])) { @@ -161,7 +162,7 @@ class shs_handler_filter_term_node_tid extends views_handler_filter_term_node_ti function admin_summary() { // Set up $this->value_options for the parent summary. - $this->value_options = array(); + $this->value_options = []; if ($this->value == 'All') { $this->value = NULL; diff --git a/includes/handlers/shs_handler_filter_term_node_tid_depth.inc b/includes/handlers/shs_handler_filter_term_node_tid_depth.inc index 99156e7..b2e63a2 100644 --- a/includes/handlers/shs_handler_filter_term_node_tid_depth.inc +++ b/includes/handlers/shs_handler_filter_term_node_tid_depth.inc @@ -16,15 +16,15 @@ */ class shs_handler_filter_term_node_tid_depth extends shs_handler_filter_term_node_tid { function operator_options($which = 'title') { - return array( + return [ 'or' => t('Is one of'), - ); + ]; } function option_definition() { $options = parent::option_definition(); - $options['depth'] = array('default' => 0); + $options['depth'] = ['default' => 0]; return $options; } @@ -32,12 +32,12 @@ class shs_handler_filter_term_node_tid_depth extends shs_handler_filter_term_nod function extra_options_form(&$form, &$form_state) { parent::extra_options_form($form, $form_state); - $form['depth'] = array( + $form['depth'] = [ '#type' => 'weight', '#title' => t('Depth'), '#default_value' => $this->options['depth'], '#description' => t('The depth will match nodes tagged with terms in the hierarchy. For example, if you have the term "fruit" and a child term "apple", with a depth of 1 (or higher) then filtering for the term "fruit" will get nodes that are tagged with "apple" as well as "fruit". If negative, the reverse is true; searching for "apple" will also pick up nodes tagged with "fruit" if depth is -1 (or lower).'), - ); + ]; } function query() { diff --git a/js/shs.js b/js/shs.js index 428711e..865d1a3 100644 --- a/js/shs.js +++ b/js/shs.js @@ -125,6 +125,9 @@ cache: true, data: { callback: 'shs_json_term_get_children', + js_module: 'shs', + js_callback: 'json', + js_token: Drupal.settings.js && Drupal.settings.js.tokens && Drupal.settings.js.tokens['shs-json'], arguments: { vid: settings.vid, parent: parent_value, @@ -222,6 +225,9 @@ cache: true, data: { callback: 'shs_json_term_add', + js_module: 'shs', + js_callback: 'json', + js_token: Drupal.settings.js && Drupal.settings.js.tokens && Drupal.settings.js.tokens['shs-json'], arguments: { vid: term.vid, parent: term.parent, diff --git a/modules/shs_node_count/shs_node_count.module b/modules/shs_node_count/shs_node_count.module index 4179609..95b6c84 100644 --- a/modules/shs_node_count/shs_node_count.module +++ b/modules/shs_node_count/shs_node_count.module @@ -13,9 +13,9 @@ function shs_node_count_field_widget_info_alter(&$info) { return; } // Add "a"node_count" setting to a shs widgets. - $info['taxonomy_shs']['settings']['shs'] += array( + $info['taxonomy_shs']['settings']['shs'] += [ 'node_count' => FALSE, - ); + ]; } /** @@ -28,13 +28,13 @@ function shs_node_count_form_field_ui_field_edit_form_alter(&$form, &$form_state $settings_form = &$form['instance']['widget']['settings']['shs']; $settings = &$form['#instance']['widget']['settings']['shs']; - $settings_form['node_count'] = array( + $settings_form['node_count'] = [ '#type' => 'checkbox', '#title' => t('Display number of nodes'), '#description' => t('Display the number of nodes associated with the term.'), '#default_value' => empty($settings['node_count']) ? FALSE : $settings['node_count'], '#weight' => -1, - ); + ]; } /** @@ -46,10 +46,10 @@ function shs_node_count_shs_term_get_children_alter(&$terms, &$alter_options) { return; } $langcode = $alter_options['settings']['language']->language; - $term = (object) array( + $term = (object) [ 'vid' => $alter_options['vid'], 'tid' => 0, - ); + ]; $format = variable_get('shs_node_count_format', '%s (%d)'); foreach ($terms as &$item) { array_walk($item[$langcode][$alter_options['parent']], function (&$name, $key) use ($term, $format) { @@ -72,7 +72,7 @@ function shs_node_count_shs_term_get_children_alter(&$terms, &$alter_options) { * Number of nodes within the term. */ function shs_node_count_term_get_node_count($term, $count_children = FALSE) { - $num_nodes = &drupal_static(__FUNCTION__, array()); + $num_nodes = &drupal_static(__FUNCTION__, []); // Maybe this needs some more caching and value-updates on node_save()/ // _update()/delete(). @@ -90,7 +90,7 @@ function shs_node_count_term_get_node_count($term, $count_children = FALSE) { ->rowCount(); if ($count_children) { - $tids = array(); + $tids = []; $tree = taxonomy_get_tree($term->vid, $term->tid); foreach ($tree as $child_term) { $tids[] = $child_term->tid; diff --git a/shs.api.php b/shs.api.php index d5a7baa..4c8098b 100644 --- a/shs.api.php +++ b/shs.api.php @@ -108,11 +108,11 @@ function hook_shs_FIELDNAME_js_settings_alter(&$settings_js, $field_name, $vocab foreach ($settings_js['shs'] as $field => &$container) { foreach ($container as $identifier => &$settings) { // Define labels for each level. - $settings['labels'] = array( + $settings['labels'] = [ FALSE, // No label for first level. t('Country'), t('City'), - ); + ]; // Small speed-up for anmiations (defaults to 400ms). $settings['display']['animationSpeed'] = 100; } diff --git a/shs.info b/shs.info index 37e775d..9cccde0 100644 --- a/shs.info +++ b/shs.info @@ -1,5 +1,6 @@ name = Simple hierarchical select core = 7.x +php = 5.3 description = Creates a simple hierarchical select widget for taxonomy fields. dependencies[] = taxonomy files[] = includes/handlers/shs_handler_filter_entityreference.inc diff --git a/shs.module b/shs.module index 486b717..ddaf357 100644 --- a/shs.module +++ b/shs.module @@ -9,89 +9,103 @@ * Implements hook_menu(). */ function shs_menu() { - $items = array(); + $items = []; // Create menu item for JSON callbacks. - $items['js/shs'] = array( + $items['js/shs'] = [ 'title' => 'JSON callback', 'description' => 'JSON callbacks for Simple hierarchical select', - 'page callback' => 'shs_json', + 'page callback' => 'shs_js_callback_json', 'access callback' => 'user_access', - 'access arguments' => array('access content'), + 'access arguments' => ['access content'], 'type' => MENU_CALLBACK, - ); + ]; return $items; } /** - * Implements hook_js(). + * Implements hook_js_info(). */ -function shs_js() { - $settings = array( - 'json' => array( - 'callback' => 'shs_json', +function shs_js_info() { + $info = [ + 'json' => [ 'access callback' => 'user_access', - 'access arguments' => array('access content'), - 'includes' => array('path'), - 'dependencies' => array('taxonomy', 'field', 'field_sql_storage'), - ), - ); - drupal_alter('shs_js_info', $settings); - return $settings; + 'access arguments' => ['access content'], + 'includes' => ['path'], + 'dependencies' => ['taxonomy', 'field', 'field_sql_storage'], + // Since options may be added by the widget we do not want to escape HTML. + 'xss' => FALSE, + ], + ]; + drupal_alter('shs_js_info', $info); + return $info; } /** * Implements hook_requirements(). */ function shs_requirements($phase) { - $requirements = array(); + $requirements = []; $t = get_t(); - if ($phase !== 'runtime' || !module_exists('chosen')) { + if ('runtime' !== $phase) { return $requirements; } - if (($info = drupal_get_library('chosen', 'chosen')) === FALSE) { - return $requirements; + + if (module_exists('chosen') && ($info = drupal_get_library('chosen', 'chosen'))) { + // Check for minimum version of chosen. + if (version_compare($info['version'], '1.1.0', '<')) { + $requirements['shs'] = [ + 'title' => $t('Simple hierarchical select: chosen integration'), + 'description' => $t('If you would like to use chosen with Simple hierarchical select you need to install at least version 1.1.0 of !chosen_library.', ['!chosen_library' => l('Chosen', 'http://harvesthq.github.io/chosen/')]), + 'severity' => REQUIREMENT_WARNING, + 'value' => $t('Chosen library too old (installed version is !version)', ['!version' => $info['version']]), + ]; + } } - // Chosen version should be at least 1.0. - if (version_compare($info['version'], '1.1.0') < 0) { - $requirements['shs'] = array( - 'title' => $t('Simple hierarchical select: chosen integration'), - 'description' => $t('If you would like to use chosen with Simple hierarchical select you need to install at least version 1.1.0 of !chosen_library.', array('!chosen_library' => l('Chosen', 'http://harvesthq.github.io/chosen/'))), - 'severity' => REQUIREMENT_WARNING, - 'value' => $t('Chosen library too old (installed version is !version)', array('!version' => $info['version'])), - ); + if (module_exists('js') && ($info = system_get_info('module', 'js'))) { + // Check for minimum version of js. + if (version_compare($info['version'], '7.x-2.x', '<')) { + $requirements['shs'] = [ + 'title' => $t('Simple hierarchical select: js integration'), + 'description' => $t('Using version 7.x-1.x of !js is a security risk and is not supported by !shs anymore.', ['!js' => l('JS Callback Handler', 'https://www.drupal.org/project/js'), '!js' => l('SHS', 'https://www.drupal.org/project/shs')]), + 'severity' => REQUIREMENT_ERROR, + 'value' => $t('JS module unsupported (installed version is !version)', ['!version' => $info['version']]), + ]; + } } - return $requirements; } /** - * Menu callback to get data in JSON format. + * Implements hook_js_callback_CALLBACK(). */ -function shs_json() { - $result = array( +function shs_js_callback_json() { + $json = [ 'success' => FALSE, - 'data' => array(), - ); - if (isset($_POST['callback'])) { - // Get name of function we need to call to get the data. - $_callback = check_plain($_POST['callback']); - // Is this a valid callback? - $valid_callbacks = shs_json_callbacks(); - if (isset($valid_callbacks[$_callback]) && !empty($valid_callbacks[$_callback]['callback']) && function_exists($valid_callbacks[$_callback]['callback'])) { - // Get arguments and validate them. - $post_args = (isset($_POST['arguments']) && is_array($_POST['arguments'])) ? $_POST['arguments'] : array(); - $arguments = _shs_json_callback_get_arguments($valid_callbacks[$_callback], $post_args); - if (($callback_result = call_user_func_array($valid_callbacks[$_callback]['callback'], $arguments)) !== FALSE) { - $result['success'] = TRUE; - $result['data'] = $callback_result; - } - } + 'data' => [], + ]; + $_callback = check_plain($_POST['callback']); + + if (empty($_callback)) { + return $json; + } + // Is the given name a valid callback? + $valid_callbacks = shs_json_callbacks(); + if (empty($valid_callbacks[$_callback]) || empty($valid_callbacks[$_callback]['callback']) || !function_exists($valid_callbacks[$_callback]['callback'])) { + return $json; } - // Return result as JSON string. - drupal_json_output($result); + + // Get arguments and validate them. + $post_args = (isset($_POST['arguments']) && is_array($_POST['arguments'])) ? $_POST['arguments'] : []; + $arguments = _shs_json_callback_get_arguments($valid_callbacks[$_callback], $post_args); + if (($callback_result = call_user_func_array($valid_callbacks[$_callback]['callback'], $arguments)) !== FALSE) { + $json['success'] = TRUE; + $json['data'] = $callback_result; + } + + return $json; } /** @@ -105,26 +119,26 @@ function shs_json() { * - [name of argument]: [validation function] (FALSE for no validation) */ function shs_json_callbacks() { - $callbacks = array( - 'shs_json_term_get_children' => array( + $callbacks = [ + 'shs_json_term_get_children' => [ 'callback' => 'shs_json_term_get_children', - 'arguments' => array( + 'arguments' => [ 'vid' => 'shs_json_validation_vocabulary_identifier', 'parent' => 'is_array', 'settings' => 'is_array', 'field' => 'is_string', - ), - ), - 'shs_json_term_add' => array( + ], + ], + 'shs_json_term_add' => [ 'callback' => 'shs_json_term_add', - 'arguments' => array( + 'arguments' => [ 'vid' => 'shs_json_validation_vocabulary_identifier', 'parent' => 'is_numeric', 'name' => 'is_string', 'field' => 'is_string', - ), - ), - ); + ], + ], + ]; // Let other modules add some more callbacks and alter the existing. drupal_alter('shs_json_callbacks', $callbacks); return $callbacks; @@ -143,7 +157,7 @@ function shs_json_callbacks() { * for this callback will be removed. */ function _shs_json_callback_get_arguments($callback, $arguments) { - $result = array(); + $result = []; // Get arguments from callback definition. $callback_arguments = $callback['arguments']; foreach ($arguments as $key => $value) { @@ -168,21 +182,21 @@ function _shs_json_callback_get_arguments($callback, $arguments) { */ function shs_views_data_alter(&$data) { // Add filter handler for term ID with depth. - $data['node']['shs_term_node_tid_depth'] = array( + $data['node']['shs_term_node_tid_depth'] = [ 'help' => t('Display content if it has the selected taxonomy terms, or children of the selected terms. Due to additional complexity, this has fewer options than the versions without depth. Optionally the filter will use a simple hierarchical select for the selection of terms.'), 'real field' => 'nid', - 'filter' => array( - 'title' => t('Has taxonomy terms (with depth; @type)', array('@type' => 'Simple hierarchical select')), + 'filter' => [ + 'title' => t('Has taxonomy terms (with depth; @type)', ['@type' => 'Simple hierarchical select']), 'handler' => 'shs_handler_filter_term_node_tid_depth', - ), - ); + ], + ]; } /** * Implements hook_field_views_data_alter(). */ function shs_field_views_data_alter(&$result, &$field, $module) { - if (empty($field['columns']) || !in_array($field['type'], array('taxonomy_term_reference', 'entityreference'))) { + if (empty($field['columns']) || !in_array($field['type'], ['taxonomy_term_reference', 'entityreference'])) { return; } if ($field['type'] == 'entityreference' && (empty($field['settings']['target_type']) || $field['settings']['target_type'] != 'taxonomy_term')) { @@ -205,15 +219,15 @@ function shs_field_views_data_alter(&$result, &$field, $module) { * Implements hook_conditional_fields_states_handlers_alter(). */ function shs_conditional_fields_states_handlers_alter(&$handlers) { - $handlers += array( - 'shs_conditional_fields_states_handler_shs' => array( - array( - 'tid' => array( + $handlers += [ + 'shs_conditional_fields_states_handler_shs' => [ + [ + 'tid' => [ '#type' => 'select', - ), - ), - ), - ); + ], + ], + ], + ]; } /** @@ -244,11 +258,11 @@ function shs_conditional_fields_states_handler_shs($field, $field_info, &$option case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT: case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR: foreach ($options['values'] as $value) { - $select_states[$options['state']][] = array( - $options['selector'] => array( - $options['condition'] => empty($regex) ? array($value) : $options['value'], - ), - ); + $select_states[$options['state']][] = [ + $options['selector'] => [ + $options['condition'] => empty($regex) ? [$value] : $options['value'], + ], + ]; } break; } @@ -260,19 +274,19 @@ function shs_conditional_fields_states_handler_shs($field, $field_info, &$option * Implements hook_field_widget_info(). */ function shs_field_widget_info() { - return array( - 'taxonomy_shs' => array( + return [ + 'taxonomy_shs' => [ 'label' => t('Simple hierarchical select'), - 'field types' => array('taxonomy_term_reference', 'entityreference'), - 'settings' => array( - 'shs' => array( + 'field types' => ['taxonomy_term_reference', 'entityreference'], + 'settings' => [ + 'shs' => [ 'create_new_terms' => FALSE, 'create_new_levels' => FALSE, 'force_deepest' => FALSE, - ), - ), - ), - ); + ], + ], + ], + ]; } /** @@ -309,9 +323,9 @@ function shs_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) function shs_entityreference_field_settings_process($form, $form_state) { if (!empty($form['target_type'])) { // Reduce list of available target types to taxonomy terms. - $form['target_type']['#options'] = array( + $form['target_type']['#options'] = [ 'taxonomy_term' => t('Taxonomy term'), - ); + ]; } return $form; } @@ -323,55 +337,55 @@ function shs_field_widget_settings_form($field, $instance) { $widget = $instance['widget']; $settings = $widget['settings']; - $form = array(); + $form = []; - $form['shs'] = array( + $form['shs'] = [ '#type' => 'fieldset', '#title' => 'Simple hierarchical select settings', '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, - ); + ]; if ($field['type'] != 'entityreference' || ($field['type'] == 'entityreference' && !empty($field['settings']['handler_settings']['target_bundles']) && count($field['settings']['handler_settings']['target_bundles']) == 1)) { - $form['shs']['create_new_terms'] = array( + $form['shs']['create_new_terms'] = [ '#type' => 'checkbox', '#title' => t('Allow creating new terms'), '#description' => t('If checked the user will be able to create new terms (permission to edit terms in this vocabulary must be set).'), '#default_value' => empty($settings['shs']['create_new_terms']) ? FALSE : $settings['shs']['create_new_terms'], - ); - $form['shs']['create_new_levels'] = array( + ]; + $form['shs']['create_new_levels'] = [ '#type' => 'checkbox', '#title' => t('Allow creating new levels'), '#description' => t('If checked the user will be able to create new children for items which do not have any children yet (permission to edit terms in this vocabulary must be set).'), '#default_value' => empty($settings['shs']['create_new_levels']) ? FALSE : $settings['shs']['create_new_levels'], - '#states' => array( - 'visible' => array( - ':input[name="instance[widget][settings][shs][create_new_terms]"]' => array('checked' => TRUE), - ), - ), - ); + '#states' => [ + 'visible' => [ + ':input[name="instance[widget][settings][shs][create_new_terms]"]' => ['checked' => TRUE], + ], + ], + ]; } - $form['shs']['force_deepest'] = array( + $form['shs']['force_deepest'] = [ '#type' => 'checkbox', '#title' => t('Force selection of deepest level'), '#description' => t('If checked the user will be forced to select terms from the deepest level.'), '#default_value' => empty($settings['shs']['force_deepest']) ? FALSE : $settings['shs']['force_deepest'], - ); + ]; // "Chosen" integration. if (module_exists('chosen')) { - $form['shs']['use_chosen'] = array( + $form['shs']['use_chosen'] = [ '#type' => 'select', - '#title' => t('Output this field with !chosen', array('!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen'))), - '#description' => t('Select in which cases the element will use the !chosen module for the term selection of each level.', array('!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen'))), + '#title' => t('Output this field with !chosen', ['!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen')]), + '#description' => t('Select in which cases the element will use the !chosen module for the term selection of each level.', ['!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen')]), '#default_value' => empty($settings['shs']['use_chosen']) ? 'chosen' : $settings['shs']['use_chosen'], - '#options' => array( + '#options' => [ 'chosen' => t('let chosen decide'), 'always' => t('always'), 'never' => t('never'), - ), - ); + ], + ]; } return $form; @@ -401,13 +415,13 @@ function shs_field_widget_form(&$form, &$form_state, $field, $instance, $langcod } elseif (!empty($submitted_value)) { // Use value from form_state (for example for fields with cardinality = -1). - $element_value = array('tid' => $submitted_value); + $element_value = ['tid' => $submitted_value]; } // Get vocabulary names from allowed values. if ($field['type'] == 'entityreference') { if ('views' === $field['settings']['handler']) { - $vocabulary_names = array(); + $vocabulary_names = []; $view_settings = $field['settings']['handler_settings']['view']; // Try to load vocabularies from view filter. $vocabulary_names = _shs_entityreference_views_get_vocabularies($view_settings['view_name'], $view_settings['display_name']); @@ -422,16 +436,16 @@ function shs_field_widget_form(&$form, &$form_state, $field, $instance, $langcod } if (empty($vocabulary_names) && 'views' !== $field['settings']['handler']) { // No vocabulary selected yet. - return array(); + return []; } if (!is_array($vocabulary_names)) { - $vocabulary_names = array($vocabulary_names); + $vocabulary_names = [$vocabulary_names]; } - $vocabularies = array(); + $vocabularies = []; foreach ($vocabulary_names as $vocabulary_name) { if (($vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_name)) === FALSE) { // Vocabulary not found. Stop here. - return array(); + return []; } $vocabularies[] = $vocabulary; } @@ -454,9 +468,9 @@ function shs_field_widget_form(&$form, &$form_state, $field, $instance, $langcod // Get current selection handler. $handler = entityreference_get_selection_handler($field, $instance, $element['#entity_type'], $element['#entity']); $referencable_entities = $handler->getReferencableEntities(); - $options = array( - '_none' => empty($element['#required']) ? t('- None -', array(), array('context' => 'shs')) : t('- Select a value -', array(), array('context' => 'shs')), - ); + $options = [ + '_none' => empty($element['#required']) ? t('- None -', [], ['context' => 'shs']) : t('- Select a value -', [], ['context' => 'shs']), + ]; foreach ($referencable_entities as $v_name => $terms) { $options += $terms; } @@ -466,22 +480,24 @@ function shs_field_widget_form(&$form, &$form_state, $field, $instance, $langcod $options = _options_get_options($field, $instance, $properties, $element['#entity_type'], $element['#entity']); } // Create element. - $element += array( + $element += [ '#type' => 'select', '#default_value' => empty($element_value) ? NULL : $element_value, '#options' => $options, - '#attributes' => array( - 'class' => array('shs-enabled'), - ), + '#attributes' => [ + 'class' => ['shs-enabled'], + ], // Prevent errors with drupal_strlen(). '#maxlength' => NULL, - '#element_validate' => array('shs_field_widget_validate'), - '#after_build' => array('shs_field_widget_afterbuild'), + '#element_validate' => ['shs_field_widget_validate'], + '#after_build' => ['shs_field_widget_afterbuild'], '#shs_settings' => $instance['widget']['settings']['shs'], '#shs_vocabularies' => $vocabularies, - ); + // Generates the necessary XSS token to validate JS 2.x requests. + '#js_callback' => ['shs' => 'json'], + ]; - $return = array($field_column => $element); + $return = [$field_column => $element]; if (!empty($element['#title'])) { // Set title to "parent" element to enable label translation. $return['#title'] = $element['#title']; @@ -493,7 +509,7 @@ function shs_field_widget_form(&$form, &$form_state, $field, $instance, $langcod * Afterbuild callback for widgets of type "taxonomy_shs". */ function shs_field_widget_afterbuild($element, &$form_state) { - $js_added = &drupal_static(__FUNCTION__ . '_js_added', array()); + $js_added = &drupal_static(__FUNCTION__ . '_js_added', []); // Generate a random hash to avoid merging of settings by drupal_add_js. // This is necessary until http://drupal.org/node/208611 lands for D7. $js_hash = &drupal_static(__FUNCTION__ . '_js_hash'); @@ -502,7 +518,7 @@ function shs_field_widget_afterbuild($element, &$form_state) { $js_hash = _shs_create_hash(); } - $parents = array(); + $parents = []; // Get default value from form state and set it to element. $default_value = drupal_array_get_nested_value($form_state['values'], $element['#parents']); if (!empty($default_value)) { @@ -526,13 +542,13 @@ function shs_field_widget_afterbuild($element, &$form_state) { // Ensure field is rendered if it is required but not selected. if (empty($element_value) || $element_value == '_none') { // Add fake parent for new items or field required submit fail. - $parents[] = array('tid' => 0); + $parents[] = ['tid' => 0]; } else { $term_parents = taxonomy_get_parents_all($element_value); foreach ($term_parents as $term) { // Create term lineage. - $parents[] = array('tid' => $term->tid); + $parents[] = ['tid' => $term->tid]; } } @@ -543,34 +559,34 @@ function shs_field_widget_afterbuild($element, &$form_state) { $vocabulary_identifier = $vocabularies[0]->vid; } else { - $vocabulary_identifier = array( + $vocabulary_identifier = [ 'field_name' => $element['#field_name'], - ); + ]; } // Create settings needed for our js magic. - $settings_js = array( - 'shs' => array( - "{$element['#name']}" => array( - $js_hash => array( + $settings_js = [ + 'shs' => [ + "{$element['#name']}" => [ + $js_hash => [ 'vid' => $vocabulary_identifier, 'settings' => $element['#shs_settings'], 'default_value' => $element['#default_value'], 'parents' => array_reverse($parents), - 'any_label' => empty($element['#required']) ? t('- None -', array(), array('context' => 'shs')) : t('- Select a value -', array(), array('context' => 'shs')), + 'any_label' => empty($element['#required']) ? t('- None -', [], ['context' => 'shs']) : t('- Select a value -', [], ['context' => 'shs']), 'any_value' => '_none', - ), - ), - ), - ); + ], + ], + ], + ]; // Allow other modules to alter these settings. - drupal_alter(array('shs_js_settings', "shs_{$element['#field_name']}_js_settings"), $settings_js, $element['#field_name'], $vocabulary_identifier); + drupal_alter(['shs_js_settings', "shs_{$element['#field_name']}_js_settings"], $settings_js, $element['#field_name'], $vocabulary_identifier); // Add settings. drupal_add_js($settings_js, 'setting'); if (empty($js_added[$element['#name']])) { - $js_added[$element['#name']] = array(); + $js_added[$element['#name']] = []; } $js_added[$element['#name']][$js_hash] = TRUE; } @@ -591,7 +607,7 @@ function shs_field_widget_validate($element, &$form_state, $form) { } // Load default settings. - $settings = empty($instance['widget']['settings']['shs']) ? array() : $instance['widget']['settings']['shs']; + $settings = empty($instance['widget']['settings']['shs']) ? [] : $instance['widget']['settings']['shs']; if (!empty($element['#shs_settings'])) { // Use settings directly applied to widget (possibly overridden in // hook_field_widget_form_alter() or @@ -609,7 +625,7 @@ function shs_field_widget_validate($element, &$form_state, $form) { } if ($element['#required'] && $value == '_none') { $element_name = empty($element['#title']) ? $instance['label'] : $element['#title']; - form_error($element, t('!name field is required.', array('!name' => $element_name))); + form_error($element, t('!name field is required.', ['!name' => $element_name])); return; } if ($force_deepest_level && $value) { @@ -623,21 +639,21 @@ function shs_field_widget_validate($element, &$form_state, $form) { } if (empty($vocabulary_names)) { // No vocabulary selected yet. - form_error($element, t('No vocabulary is configured as source for field %field_name.', array('%field_name' => $instance['label'], '%field_machine_name' => $field_name))); + form_error($element, t('No vocabulary is configured as source for field %field_name.', ['%field_name' => $instance['label'], '%field_machine_name' => $field_name])); } if (!is_array($vocabulary_names)) { - $vocabulary_names = array($vocabulary_names); + $vocabulary_names = [$vocabulary_names]; } foreach ($vocabulary_names as $vocabulary_name) { if (($vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_name)) === FALSE) { // Vocabulary not found. Stop here. - form_error($element, t('Vocabulary %machine_name is configured as source for field %field_name but could not be found.', array('%machine_name' => $vocabulary_name, '%field_name' => $instance['label'], '%field_machine_name' => $field_name))); + form_error($element, t('Vocabulary %machine_name is configured as source for field %field_name but could not be found.', ['%machine_name' => $vocabulary_name, '%field_name' => $instance['label'], '%field_machine_name' => $field_name])); return; } // Does the selected term has any children? $children = shs_term_get_children($vocabulary->vid, $value); if (count($children)) { - form_error($element, t('You need to select a term from the deepest level in field %field_name.', array('%field_name' => $instance['label'], '%field_machine_name' => $field_name))); + form_error($element, t('You need to select a term from the deepest level in field %field_name.', ['%field_name' => $instance['label'], '%field_machine_name' => $field_name])); return; } } @@ -648,15 +664,15 @@ function shs_field_widget_validate($element, &$form_state, $form) { * Implements hook_field_formatter_info(). */ function shs_field_formatter_info() { - return array( - 'shs_default' => array( + return [ + 'shs_default' => [ 'label' => t('Simple hierarchy'), - 'field types' => array('taxonomy_term_reference', 'entityreference'), - 'settings' => array( + 'field types' => ['taxonomy_term_reference', 'entityreference'], + 'settings' => [ 'linked' => FALSE, - ), - ), - ); + ], + ], + ]; } /** @@ -666,14 +682,14 @@ function shs_field_formatter_settings_form($field, $instance, $view_mode, $form, $display = $instance['display'][$view_mode]; $settings = $display['settings']; - $element = array(); + $element = []; if ($display['type'] == 'shs_default') { - $element['linked'] = array( + $element['linked'] = [ '#title' => t('Link to term page'), '#type' => 'checkbox', '#default_value' => $settings['linked'], - ); + ]; } return $element; @@ -689,7 +705,7 @@ function shs_field_formatter_settings_summary($field, $instance, $view_mode) { $summary = ''; if ($display['type'] == 'shs_default') { - $summary = t('Linked to term page: !linked', array('!linked' => $settings['linked'] ? t('Yes') : t('No'))); + $summary = t('Linked to term page: !linked', ['!linked' => $settings['linked'] ? t('Yes') : t('No')]); } return $summary; @@ -705,7 +721,7 @@ function shs_field_formatter_prepare_view($entity_type, $entities, $field, $inst return; } foreach ($items[$entity_id] as $delta => $item) { - $items[$entity_id][$delta]['parents'] = array(); + $items[$entity_id][$delta]['parents'] = []; // Load list of parent terms. $parents = taxonomy_get_parents_all($item[$field_column]); // Remove current term from list. @@ -732,7 +748,7 @@ function shs_field_formatter_prepare_view($entity_type, $entities, $field, $inst * Implements hook_field_formatter_view(). */ function shs_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { - $elements = array(); + $elements = []; $settings = $display['settings']; if (empty($items) || $instance['widget']['type'] != 'taxonomy_shs') { @@ -745,26 +761,26 @@ function shs_field_formatter_view($entity_type, $entity, $field, $instance, $lan if (empty($item['term'])) { continue; } - $list_items = array(); + $list_items = []; // Add parent term names. foreach ($item['parents'] as $parent) { - $list_items[] = array( + $list_items[] = [ 'data' => $settings['linked'] ? l($parent->name, "taxonomy/term/{$parent->tid}") : $parent->name, - 'class' => array('shs-parent'), - ); + 'class' => ['shs-parent'], + ]; }; // Add name of selected term. - $list_items[] = array( + $list_items[] = [ 'data' => $settings['linked'] ? l($item['term']->name, "taxonomy/term/{$item['term']->tid}") : $item['term']->name, - 'class' => array('shs-term-selected'), - ); - $elements[$delta] = array( + 'class' => ['shs-term-selected'], + ]; + $elements[$delta] = [ '#items' => $list_items, '#theme' => 'item_list', - '#attributes' => array( + '#attributes' => [ 'class' => 'shs-hierarchy', - ), - ); + ], + ]; } // Add basic style. @@ -797,7 +813,7 @@ function shs_field_formatter_view($entity_type, $entity, $field, $instance, $lan * @return * List of child terms keyed by term id. */ -function shs_term_get_children($identifier, $parent = 0, $settings = array(), $reset = FALSE) { +function shs_term_get_children($identifier, $parent = 0, $settings = [], $reset = FALSE) { global $language; $langcode = $language->language; if (empty($settings['language']->language)) { @@ -807,13 +823,13 @@ function shs_term_get_children($identifier, $parent = 0, $settings = array(), $r $langcode = $settings['language']->language; } - $vocabularies = array(); + $vocabularies = []; $vocabulary_cache_key = NULL; if (is_numeric($identifier)) { $vocabulary_cache_key = $identifier; if (($vocabulary = taxonomy_vocabulary_load($identifier)) === FALSE) { - watchdog('Simple hierarchical select', 'Unknown vocabulary with ID !vid used to get terms.', array('!vid' => $identifier)); - return array(); + watchdog('Simple hierarchical select', 'Unknown vocabulary with ID !vid used to get terms.', ['!vid' => $identifier]); + return []; } $vocabularies[$vocabulary->machine_name] = $identifier; } @@ -821,11 +837,11 @@ function shs_term_get_children($identifier, $parent = 0, $settings = array(), $r $vocabulary_cache_key = $identifier['field_name']; } - $terms = &drupal_static(__FUNCTION__, array()); + $terms = &drupal_static(__FUNCTION__, []); if ($reset || ($vocabulary_cache_key && empty($terms[$vocabulary_cache_key][$langcode][$parent]))) { // Initialize list. - $terms[$vocabulary_cache_key][$langcode][$parent] = array(); + $terms[$vocabulary_cache_key][$langcode][$parent] = []; $cache_key = "shs:{$vocabulary_cache_key}"; // Get cached values. $cache = cache_get($cache_key); @@ -836,7 +852,7 @@ function shs_term_get_children($identifier, $parent = 0, $settings = array(), $r $terms[$vocabulary_cache_key] = $cache->data; } if ($reset) { - $terms[$vocabulary_cache_key][$langcode][$parent] = array(); + $terms[$vocabulary_cache_key][$langcode][$parent] = []; } if (!is_numeric($vocabulary_cache_key) && is_array($identifier)) { @@ -877,14 +893,14 @@ function shs_term_get_children($identifier, $parent = 0, $settings = array(), $r } } // Allow other module to modify the list of terms. - $alter_options = array( + $alter_options = [ 'vid' => $vocabulary_cache_key, 'parent' => $parent, 'settings' => $settings, - ); + ]; drupal_alter('shs_term_get_children', $terms, $alter_options); - return empty($terms[$vocabulary_cache_key][$langcode][$parent]) ? array() : $terms[$vocabulary_cache_key][$langcode][$parent]; + return empty($terms[$vocabulary_cache_key][$langcode][$parent]) ? [] : $terms[$vocabulary_cache_key][$langcode][$parent]; } /** @@ -904,25 +920,25 @@ function shs_term_get_children($identifier, $parent = 0, $settings = array(), $r * * @see shs_term_get_children() */ -function shs_json_term_get_children($vid, $parent = array(), $settings = array(), $field = NULL) { - $scope = $result = array(); +function shs_json_term_get_children($vid, $parent = [], $settings = [], $field = NULL) { + $scope = $result = []; foreach ($parent as $tid) { $scope[] = shs_term_get_children($vid, $tid, $settings); if (shs_add_term_access($vid, $tid, $field)) { - $result[] = array( + $result[] = [ 'vid' => $vid, - ); + ]; } } // Rewrite result set to preserve original sort of terms through JSON request. foreach ($scope as $terms) { foreach ($terms as $tid => $label) { - $result[] = array( + $result[] = [ 'tid' => $tid, 'label' => $label, 'has_children' => shs_term_has_children($tid, $vid), - ); + ]; } } @@ -994,17 +1010,17 @@ function shs_json_term_add($vid, $parent, $term_name, $field = NULL) { return FALSE; } - $term = (object) array( - 'vid' => $vid, - 'parent' => $parent, - 'name' => str_replace('&', '&', filter_xss($term_name)), - 'language' => $language_content->language, - ); + $term = (object) [ + 'vid' => $vid, + 'parent' => $parent, + 'name' => str_replace('&', '&', filter_xss($term_name)), + 'language' => $language_content->language, + ]; // Save term. $status = taxonomy_term_save($term); // Return term object or FALSE (in case of errors). - return ($status == SAVED_NEW) ? array('tid' => $term->tid, 'name' => $term->name) : FALSE; + return ($status == SAVED_NEW) ? ['tid' => $term->tid, 'name' => $term->name] : FALSE; } /** @@ -1077,7 +1093,7 @@ function shs_form_taxonomy_form_term_submit(&$form, &$form_state) { * List of instances keyed by field name. */ function _shs_get_instances($entity_type, $bundle = NULL) { - $instances = array(); + $instances = []; $field_instances = field_info_instances($entity_type, $bundle); // Get all field instances with widget type "shs_taxonomy". if (empty($bundle)) { @@ -1150,10 +1166,10 @@ function _shs_entityreference_views_get_vocabularies($view_name, $display_id) { $view = views_get_view($view_name); if (empty($view)) { // Failed to load view. - return array(); + return []; } $filters = $view->get_items('filter', $display_id); - $vocabularies = array(); + $vocabularies = []; foreach ($filters as $key => $filter) { if (('taxonomy_vocabulary' !== $filter['table']) || ('machine_name' !== $key)) { continue;