summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormunavijayalakshmi2017-05-04 17:11:01 -0700
committerPat Diven II2017-05-04 17:11:01 -0700
commit8cddeef4c533351c93e571b7ee63d9c774aaec61 (patch)
tree2e354bdcec06528bef51830463c7600be6042261
parentff9c059ff1c723b28c981ae6e00a56d398705681 (diff)
Issue #2875650 by Munavijayalakshmi, dhruveshdtripathi: Convert module to use short array syntax (new coding standard)
-rw-r--r--addtoany.module28
-rw-r--r--addtoany.views.inc8
-rw-r--r--src/Form/AddToAnySettingsForm.php96
-rw-r--r--src/Plugin/Block/AddToAnyBlock.php10
-rw-r--r--src/Plugin/views/field/NodeAddToAnyShare.php4
5 files changed, 73 insertions, 73 deletions
diff --git a/addtoany.module b/addtoany.module
index a601800..de42546 100644
--- a/addtoany.module
+++ b/addtoany.module
@@ -17,29 +17,29 @@ use Drupal\node\Entity\Node;
* Implements hook_theme().
*/
function addtoany_theme() {
- return array(
- 'addtoany_standard' => array(
- 'variables' => array(
+ return [
+ 'addtoany_standard' => [
+ 'variables' => [
'addtoany_html' => FALSE,
- ),
- ),
- );
+ ],
+ ],
+ ];
}
/**
* Implements hook_entity_extra_field_info().
*/
function addtoany_entity_extra_field_info() {
- $extra = array();
+ $extra = [];
/** @var \Drupal\node\NodeTypeInterface $bundle */
foreach (NodeType::loadMultiple() as $bundle) {
- $extra['node'][$bundle->id()]['display']['addtoany'] = array(
+ $extra['node'][$bundle->id()]['display']['addtoany'] = [
'label' => t('AddToAny'),
'description' => t('Share buttons by AddToAny'),
'weight' => 5,
'visible' => FALSE,
- );
+ ];
}
return $extra;
@@ -50,13 +50,13 @@ function addtoany_entity_extra_field_info() {
*/
function addtoany_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
if ($display->getComponent('addtoany') && $node->isPublished()) {
- $build['addtoany'] = array(
+ $build['addtoany'] = [
// Not using #markup because data attribute name gets mangled
// @see https://www.drupal.org/node/2609928
// '#markup' => addtoany_create_node_buttons($node),
'#addtoany_html' => addtoany_create_node_buttons($node),
'#theme' => 'addtoany_standard',
- );
+ ];
}
}
@@ -147,7 +147,7 @@ function addtoany_page_attachments(&$page) {
* The HTML code for the buttons.
*/
function addtoany_create_node_buttons($node, $config = NULL) {
- $url = isset($node) ? $node->url('canonical', array('absolute' => true)) : NULL;
+ $url = isset($node) ? $node->url('canonical', ['absolute' => true]) : NULL;
$title = isset($node) ? $node->label() : NULL;
return addtoany_create_buttons($url, $title, $config);
}
@@ -204,7 +204,7 @@ function addtoany_create_buttons($url = NULL, $title = NULL, $config = NULL) {
$title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
// Expecting array|string|null from getTitle
if (is_array($title)) {
- $title['#allowed_tags'] = array();
+ $title['#allowed_tags'] = [];
$title = \Drupal::service('renderer')->renderPlain($title);
}
}
@@ -266,7 +266,7 @@ function addtoany_create_buttons($url = NULL, $title = NULL, $config = NULL) {
}
}
- $buttons = str_replace(array("\r", "\n"), '', $buttons);
+ $buttons = str_replace(["\r", "\n"], '', $buttons);
return $buttons;
}
diff --git a/addtoany.views.inc b/addtoany.views.inc
index 8956e61..b971ea5 100644
--- a/addtoany.views.inc
+++ b/addtoany.views.inc
@@ -10,12 +10,12 @@
*/
function addtoany_views_data_alter(array &$data) {
// Add the addtoany link to the node fields
- $data['node']['addtoany_share'] = array(
+ $data['node']['addtoany_share'] = [
'title' => t('AddToAny share buttons'),
- 'field' => array(
+ 'field' => [
'title' => t('AddToAny share buttons'),
'help' => t('Provide share buttons for sharing the content.'),
'id' => 'node_addtoany_share',
- ),
- );
+ ],
+ ];
}
diff --git a/src/Form/AddToAnySettingsForm.php b/src/Form/AddToAnySettingsForm.php
index a43a008..9929679 100644
--- a/src/Form/AddToAnySettingsForm.php
+++ b/src/Form/AddToAnySettingsForm.php
@@ -33,28 +33,28 @@ class AddToAnySettingsForm extends ConfigFormBase {
$button_img = '<img src="' . $base_path . drupal_get_path('module', 'addtoany') . '/images/%s" width="%d" height="%d"%s />';
- $button_options = array(
+ $button_options = [
'default' => sprintf($button_img, 'a2a_32_32.svg', 32, 32, ' class="addtoany-round-icon"'),
'custom' => t('Custom button'),
'none' => t('None'),
- );
+ ];
- $attributes_for_code = array(
- 'autocapitalize' => array('off'),
- 'autocomplete' => array('off'),
- 'autocorrect' => array('off'),
- 'spellcheck' => array('false'),
- );
+ $attributes_for_code = [
+ 'autocapitalize' => ['off'],
+ 'autocomplete' => ['off'],
+ 'autocorrect' => ['off'],
+ 'spellcheck' => ['false'],
+ ];
// Attach CSS and JS
$form['#attached']['library'][] = 'addtoany/addtoany.admin';
- $form['addtoany_button_settings'] = array(
+ $form['addtoany_button_settings'] = [
'#type' => 'details',
'#title' => t('Buttons'),
'#open' => TRUE,
- );
- $form['addtoany_button_settings']['addtoany_buttons_size'] = array(
+ ];
+ $form['addtoany_button_settings']['addtoany_buttons_size'] = [
'#type' => 'number',
'#title' => t('Icon size'),
'#field_suffix' => ' ' . t('pixels'),
@@ -64,100 +64,100 @@ class AddToAnySettingsForm extends ConfigFormBase {
'#min' => 8, // Replaces D7's element_validate_integer_positive() validation
'#max' => 999,
'#required' => TRUE,
- );
- $form['addtoany_button_settings']['addtoany_service_button_settings'] = array(
+ ];
+ $form['addtoany_button_settings']['addtoany_service_button_settings'] = [
'#type' => 'details',
'#title' => t('Service Buttons'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
- );
- $form['addtoany_button_settings']['addtoany_service_button_settings']['addtoany_additional_html'] = array(
+ ];
+ $form['addtoany_button_settings']['addtoany_service_button_settings']['addtoany_additional_html'] = [
'#type' => 'textarea',
'#title' => t('Service Buttons HTML code'),
'#default_value' => $addtoany_settings->get('additional_html'),
'#description' => t('You can add HTML code to display customized <a href="https://www.addtoany.com/buttons/customize/drupal/standalone_services" target="_blank">standalone service buttons</a> next to each universal share button. For example: <br /> <code>&lt;a class=&quot;a2a_button_facebook&quot;&gt;&lt;/a&gt;<br />&lt;a class=&quot;a2a_button_twitter&quot;&gt;&lt;/a&gt;<br />&lt;a class=&quot;a2a_button_pinterest&quot;&gt;&lt;/a&gt;</code>
'),
'#attributes' => $attributes_for_code,
- );
- $form['addtoany_button_settings']['universal_button'] = array(
+ ];
+ $form['addtoany_button_settings']['universal_button'] = [
'#type' => 'details',
'#title' => t('Universal Button'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
/* #states workaround in addtoany.admin.js */
- );
- $form['addtoany_button_settings']['universal_button']['addtoany_universal_button'] = array(
+ ];
+ $form['addtoany_button_settings']['universal_button']['addtoany_universal_button'] = [
'#type' => 'radios',
'#title' => t('Button'),
'#default_value' => $addtoany_settings->get('universal_button'),
- '#attributes' => array('class' => array('addtoany-universal-button-option')),
+ '#attributes' => ['class' => ['addtoany-universal-button-option']],
'#options' => $button_options,
- );
- $form['addtoany_button_settings']['universal_button']['addtoany_custom_universal_button'] = array(
+ ];
+ $form['addtoany_button_settings']['universal_button']['addtoany_custom_universal_button'] = [
'#type' => 'textfield',
'#title' => t('Custom button URL'),
'#default_value' => $addtoany_settings->get('custom_universal_button'),
'#description' => t('URL of the button image. Example: http://example.com/share.png'),
- '#states' => array(
+ '#states' => [
// Show only if custom button is selected
- 'visible' => array(
- ':input[name="addtoany_universal_button"]' => array('value' => 'custom'),
- ),
- ),
- );
- $form['addtoany_button_settings']['universal_button']['addtoany_universal_button_placement'] = array(
+ 'visible' => [
+ ':input[name="addtoany_universal_button"]' => ['value' => 'custom'],
+ ],
+ ],
+ ];
+ $form['addtoany_button_settings']['universal_button']['addtoany_universal_button_placement'] = [
'#type' => 'radios',
'#title' => t('Button placement'),
'#default_value' => $addtoany_settings->get('universal_button_placement'),
- '#options' => array(
+ '#options' => [
'after' => t('After the service buttons'),
'before' => t('Before the service buttons'),
- ),
- '#states' => array(
+ ],
+ '#states' => [
// Hide when universal sharing is disabled
- 'invisible' => array(
- ':input[name="addtoany_universal_button"]' => array('value' => 'none'),
- ),
- ),
- );
+ 'invisible' => [
+ ':input[name="addtoany_universal_button"]' => ['value' => 'none'],
+ ],
+ ],
+ ];
- $form['addtoany_additional_settings'] = array(
+ $form['addtoany_additional_settings'] = [
'#type' => 'details',
'#title' => t('Additional options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
- );
- $form['addtoany_additional_settings']['addtoany_additional_js'] = array(
+ ];
+ $form['addtoany_additional_settings']['addtoany_additional_js'] = [
'#type' => 'textarea',
'#title' => t('Additional JavaScript'),
'#default_value' => $addtoany_settings->get('additional_js'),
'#description' => t('You can add special JavaScript code for AddToAny. See <a href="https://www.addtoany.com/buttons/customize/drupal" target="_blank">AddToAny documentation</a>.'),
'#attributes' => $attributes_for_code,
- );
- $form['addtoany_additional_settings']['addtoany_additional_css'] = array(
+ ];
+ $form['addtoany_additional_settings']['addtoany_additional_css'] = [
'#type' => 'textarea',
'#title' => t('Additional CSS'),
'#default_value' => $addtoany_settings->get('additional_css'),
'#description' => t('You can add special CSS code for AddToAny. See <a href="https://www.addtoany.com/buttons/customize/drupal" target="_blank">AddToAny documentation</a>.'),
'#attributes' => $attributes_for_code,
- );
- $form['addtoany_additional_settings']['addtoany_no_3p'] = array(
+ ];
+ $form['addtoany_additional_settings']['addtoany_no_3p'] = [
'#type' => 'checkbox',
'#title' => t('Disable 3rd party cookies'),
'#default_value' => $addtoany_settings->get('no_3p'),
'#description' => t('Disabling may affect analytics and limit some functionality.'),
- );
+ ];
if (\Drupal::moduleHandler()->moduleExists('token')) {
- $form['tokens'] = array(
+ $form['tokens'] = [
'#theme' => 'token_tree_link',
- '#token_types' => array('node'),
+ '#token_types' => ['node'],
'#global_types' => TRUE,
'#click_insert' => TRUE,
'#show_restricted' => FALSE,
'#recursion_limit' => 3,
'#text' => t('Browse available tokens'),
- );
+ ];
}
return parent::buildForm($form, $form_state);
diff --git a/src/Plugin/Block/AddToAnyBlock.php b/src/Plugin/Block/AddToAnyBlock.php
index 47e611a..75cc6c0 100644
--- a/src/Plugin/Block/AddToAnyBlock.php
+++ b/src/Plugin/Block/AddToAnyBlock.php
@@ -23,13 +23,13 @@ class AddToAnyBlock extends BlockBase {
if (is_numeric($node)) {
$node = Node::load($node);
}
- return array(
+ return [
'#addtoany_html' => addtoany_create_node_buttons($node),
'#theme' => 'addtoany_standard',
- '#cache' => array(
- 'contexts' => array('url'),
- ),
- );
+ '#cache' => [
+ 'contexts' => ['url'],
+ ],
+ ];
}
}
diff --git a/src/Plugin/views/field/NodeAddToAnyShare.php b/src/Plugin/views/field/NodeAddToAnyShare.php
index af80f91..9b593c6 100644
--- a/src/Plugin/views/field/NodeAddToAnyShare.php
+++ b/src/Plugin/views/field/NodeAddToAnyShare.php
@@ -27,10 +27,10 @@ class NodeAddToAnyShare extends FieldPluginBase {
public function render(ResultRow $values) {
$entity = $values->_entity;
if ($entity->access('view')) {
- return array(
+ return [
'#theme' => 'addtoany_standard',
'#addtoany_html' => addtoany_create_node_buttons($entity),
- );
+ ];
}
}
}