From 67f98ab171983b673ad2264e14372fec679e9f6e Mon Sep 17 00:00:00 2001 From: Daniel Bosen Date: Mon, 4 Jul 2016 16:38:20 +0200 Subject: [PATCH] Feature/thndr 92 (#8) * Added requirements for code style checking * Applied auto formatting and simple changes --- .eslintignore | 8 ++ .eslintrc | 95 +++++++++++++++++++ .gitignore | 4 +- ad_integration.install | 16 +++- ad_integration.module | 43 +++++---- ad_integration.tokens.inc | 57 +++++------ composer.json | 3 + js/adHelper.js | 41 ++++---- js/adIntegration.js | 31 +++--- src/AdIntegration.php | 29 +++--- src/AdIntegrationInterface.php | 44 ++++----- src/Form/SettingsForm.php | 40 ++++---- src/Plugin/Block/AdvertisingSlot.php | 21 +++- .../Field/FieldFormatter/AdEmptyFormatter.php | 5 - src/Plugin/Field/FieldType/AdSettings.php | 7 +- .../Field/FieldWidget/AdSettingsWidget.php | 17 ++-- 16 files changed, 289 insertions(+), 172 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..961edb7 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,8 @@ +core/assets/vendor/**/* +core/modules/locale/tests/locale_test.js +vendor/**/* +sites/**/files/**/* +libraries/**/* +sites/**/libraries/**/* +profiles/**/libraries/**/* +**/js_test_files/**/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..7e88b38 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,95 @@ +{ + "extends": "eslint:recommended", + "env": { + "browser": true + }, + "globals": { + "Drupal": true, + "drupalSettings": true, + "drupalTranslations": true, + "domready": true, + "jQuery": true, + "_": true, + "matchMedia": true, + "Backbone": true, + "Modernizr": true, + "CKEDITOR": true + }, + "rules": { + // Errors. + "array-bracket-spacing": [2, "never"], + "block-scoped-var": 2, + "brace-style": [2, "stroustrup", {"allowSingleLine": true}], + "comma-dangle": [2, "never"], + "comma-spacing": 2, + "comma-style": [2, "last"], + "computed-property-spacing": [2, "never"], + "curly": [2, "all"], + "eol-last": 2, + "eqeqeq": [2, "smart"], + "guard-for-in": 2, + "indent": [2, 2, {"SwitchCase": 1}], + "key-spacing": [2, {"beforeColon": false, "afterColon": true}], + "keyword-spacing": [2, {"before": true, "after": true}], + "linebreak-style": [2, "unix"], + "lines-around-comment": [2, {"beforeBlockComment": true, "afterBlockComment": false}], + "new-parens": 2, + "no-array-constructor": 2, + "no-caller": 2, + "no-catch-shadow": 2, + "no-eval": 2, + "no-extend-native": 2, + "no-extra-bind": 2, + "no-extra-parens": [2, "functions"], + "no-implied-eval": 2, + "no-iterator": 2, + "no-label-var": 2, + "no-labels": 2, + "no-lone-blocks": 2, + "no-loop-func": 2, + "no-multi-spaces": 2, + "no-multi-str": 2, + "no-native-reassign": 2, + "no-nested-ternary": 2, + "no-new-func": 2, + "no-new-object": 2, + "no-new-wrappers": 2, + "no-octal-escape": 2, + "no-process-exit": 2, + "no-proto": 2, + "no-return-assign": 2, + "no-script-url": 2, + "no-sequences": 2, + "no-shadow-restricted-names": 2, + "no-spaced-func": 2, + "no-trailing-spaces": 2, + "no-undef-init": 2, + "no-undefined": 2, + "no-unused-expressions": 2, + "no-unused-vars": [2, {"vars": "all", "args": "none"}], + "no-with": 2, + "object-curly-spacing": [2, "never"], + "one-var": [2, "never"], + "quote-props": [2, "consistent-as-needed"], + "quotes": [2, "single", "avoid-escape"], + "semi": [2, "always"], + "semi-spacing": [2, {"before": false, "after": true}], + "space-before-blocks": [2, "always"], + "space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], + "space-in-parens": [2, "never"], + "space-infix-ops": 2, + "space-unary-ops": [2, { "words": true, "nonwords": false }], + "spaced-comment": [2, "always"], + "strict": 2, + "yoda": [2, "never"], + // Warnings. + "max-nested-callbacks": [1, 3], + "valid-jsdoc": [1, { + "prefer": { + "returns": "return", + "property": "prop" + }, + "requireReturn": false + }] + } +} diff --git a/.gitignore b/.gitignore index 62c8935..e0d383d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.idea/ \ No newline at end of file +/.idea +/vendor +/composer.lock diff --git a/ad_integration.install b/ad_integration.install index 31c0d84..6ef6137 100644 --- a/ad_integration.install +++ b/ad_integration.install @@ -1,7 +1,12 @@ getAll(); $schema_copy = $schema; foreach ($schema as $item_name => $item) { - list($entity_type_id, , ) = explode('.', $item_name); + list($entity_type_id, ,) = explode('.', $item_name); if (!isset($entity_types[$entity_type_id])) { continue; } foreach ($item as $table_name => $table_schema) { foreach ($table_schema as $schema_key => $schema_data) { if ($schema_key === 'fields') { - if(isset($schema_data['field_advertising_adsc_mode'])) { + if (isset($schema_data['field_advertising_adsc_mode'])) { $field_name = 'field_advertising_adsc_keyword'; $field_definition = array( 'type' => 'varchar', @@ -27,10 +32,11 @@ function ad_integration_update_8001() { ); $schema_copy[$item_name][$table_name]['fields'][$field_name] = $field_definition; if ($database->driver() == 'mysql') { - //$database_schema->addField(); + // $database_schema->addField(); try { $database_schema->addField($table_name, $field_name, $field_definition); - } catch (\Exception $e) { + } + catch (\Exception $e) { } } diff --git a/ad_integration.module b/ad_integration.module index dfb51a8..93ff87b 100644 --- a/ad_integration.module +++ b/ad_integration.module @@ -1,7 +1,11 @@ 'ad-slot-inline', 'variables' => array( 'html_id' => NULL, - 'ad_tag' => NULL + 'ad_tag' => NULL, ), ), 'ad_slot_iframe' => array( 'template' => 'ad-slot-iframe', 'variables' => array( 'html_id' => NULL, - 'ad_tag' => NULL + 'ad_tag' => NULL, ), - ) + ), ); } @@ -33,7 +37,7 @@ function ad_integration_form_node_form_alter(&$form, FormStateInterface $form_st /* Is there a better way to get the node? */ $entity = $form_state->getBuildInfo()['callback_object']->getEntity(); - /** + /* * Set group of all ad_integration_settings elements */ $has_settings = FALSE; @@ -72,9 +76,7 @@ function ad_integration_form_taxonomy_term_form_alter(&$form, FormStateInterface * Implements template_preprocess_html(). */ function ad_integration_page_attachments(array &$page) { - /** - * @var Drupal\ad_integration\AdIntegration $advertisingService - */ + /* @var Drupal\ad_integration\AdIntegration $advertisingService */ $advertisingService = \Drupal::service('ad_integration'); $ad_provider = $advertisingService->getAdProvider(); $page['#cache']['tags'] = Cache::mergeTags(isset($page['#cache']['tags']) ? $page['#cache']['tags'] : [], $advertisingService->getCacheTags()); @@ -82,16 +84,17 @@ function ad_integration_page_attachments(array &$page) { [ '#tag' => 'script', '#attributes' => [ - 'src' => '/' . drupal_get_path('module', 'ad_integration') . '/js/adHelper.js' + 'src' => '/' . drupal_get_path('module', 'ad_integration') . '/js/adHelper.js', ], ], - 'ad_helper' + 'ad_helper', ]; switch ($ad_provider) { case 'fag': _attach_fag($page, $advertisingService); break; + case 'orbyd': _attach_orbyd($page, $advertisingService); break; @@ -108,7 +111,7 @@ function _attach_orbyd(array &$page, $advertisingService) { [ '#tag' => 'script', '#attributes' => [ - 'type' => 'text/javascript' + 'type' => 'text/javascript', ], '#value' => "var adunit1 = '" . $advertisingService->getAdUnit1() . "'; var adunit2 = '" . $advertisingService->getAdUnit2() . "'; @@ -118,7 +121,7 @@ function _attach_orbyd(array &$page, $advertisingService) { var admobile = deviceIsMobile().toString(); var addevice = getDeviceType();", ], - 'advertising_config' + 'advertising_config', ]; $adengine = $advertisingService->getAdEngine(); if ($adengine) { @@ -127,10 +130,10 @@ function _attach_orbyd(array &$page, $advertisingService) { '#tag' => 'script', '#attributes' => [ 'src' => $adengine, - 'type' => 'text/javascript' + 'type' => 'text/javascript', ], ], - 'ad_orbyd_head' + 'ad_orbyd_head', ]; } } @@ -145,7 +148,7 @@ function _attach_fag(array &$page, $advertisingService) { [ '#tag' => 'script', '#attributes' => [ - 'type' => 'text/javascript' + 'type' => 'text/javascript', ], '#value' => "var adsc_adunit1 = '" . $advertisingService->getAdUnit1() . "'; var adsc_adunit2 = '" . $advertisingService->getAdUnit2() . "'; @@ -155,26 +158,26 @@ function _attach_fag(array &$page, $advertisingService) { var adsc_mobile = deviceIsMobile().toString(); var adsc_device = getDeviceType();", ], - 'advertising_config' + 'advertising_config', ]; $page['#attached']['html_head'][] = [ [ '#tag' => 'script', '#attributes' => [ - 'src' => $advertisingService->getAdContainerTag() + 'src' => $advertisingService->getAdContainerTag(), ], ], - 'container_tag' + 'container_tag', ]; $page['#attached']['html_head'][] = [ [ '#tag' => 'script', '#attributes' => [ - 'src' => $advertisingService->getAdEngine() + 'src' => $advertisingService->getAdEngine(), ], ], - 'ad_engine' + 'ad_engine', ]; $page['#attached']['library'][] = 'ad_integration/id_integration'; return $page; diff --git a/ad_integration.tokens.inc b/ad_integration.tokens.inc index beee087..8f504d1 100644 --- a/ad_integration.tokens.inc +++ b/ad_integration.tokens.inc @@ -5,11 +5,10 @@ * Builds placeholder replacement tokens for ad-related data. */ +use Drupal\node\Entity\Node; use Drupal\Component\Utility\Xss; use Drupal\taxonomy\Entity\Term; use Drupal\Core\Render\BubbleableMetadata; -use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Routing\CurrentRouteMatch; /** * Implements hook_token_info(). @@ -21,7 +20,7 @@ function ad_integration_token_info() { 'needs-data' => 'advertising', ); - // Core comment tokens + // Core comment tokens. $ad['adsc_unit1'] = array( 'name' => t("Ad unit 1"), 'description' => t("Ad unit 1."), @@ -68,64 +67,58 @@ function ad_integration_tokens($type, $tokens, array $data, array $options, Bubb } function ad_integration_get_setting($name) { - /** - * @var CurrentRouteMatch $currentRoutematch - */ + /* @var CurrentRouteMatch $currentRoutematch */ $currentRoutematch = \Drupal::service('current_route_match'); $parameters = ['node', 'taxonomy_term']; $entity = NULL; - foreach($parameters as $parameter){ - /** - * @var ContentEntityInterface $entity - */ - if($entity = $currentRoutematch->getParameter($parameter)){ + foreach ($parameters as $parameter) { + /* @var ContentEntityInterface $entity */ + if ($entity = $currentRoutematch->getParameter($parameter)) { // The Entity might not be loaded so we need to check if we only // got the entity id. if (is_numeric($entity)) { switch ($parameter) { case "node": - $entity = \Drupal\node\Entity\Node::load($entity); + $entity = Node::load($entity); break; + case "taxonomy_term": - $entity = \Drupal\taxonomy\Entity\Term::load($entity); + $entity = Term::load($entity); break; + default: break; } } - /** - * Search for ad_integration_settings field - */ + + // Search for ad_integration_settings field. foreach ($entity->getFieldDefinitions() as $fieldDefinition) { - $fieldType = $fieldDefinition->getType(); - /** - * If settings are found, check if an overridden value for the - * given setting is found and return that - */ + $fieldType = $fieldDefinition->getType(); + + // If settings are found, check if an overridden value for the + // given setting is found and return that. $overiddenSetting = get_overridden_ad_setting($name, $fieldDefinition, $entity); - if (isset($overiddenSetting)){ + if (isset($overiddenSetting)) { return $overiddenSetting; } - /** - * Check for fallback categories if no ad_integration_setting is found - */ - if(!isset($termOverride) && $fieldType === 'entity_reference' && $fieldDefinition->getSetting('target_type') === 'taxonomy_term') { + // Check for fallback categories if no ad_integration_setting is found. + if (!isset($termOverride) && $fieldType === 'entity_reference' && $fieldDefinition->getSetting('target_type') === 'taxonomy_term') { $fieldName = $fieldDefinition->getName(); - if($tid = $entity->$fieldName->target_id) { + if ($tid = $entity->$fieldName->target_id) { if ($term = Term::load($tid)) { $termOverride = get_overridden_ad_setting_from_term($name, $term); } } } } - /** - * If we not returned before, it is possible, that we found a termOverride - */ - if(isset($termOverride)) { + + // If we not returned before, it is possible, + // that we found a termOverride. + if (isset($termOverride)) { return $termOverride; } } @@ -158,7 +151,7 @@ function get_overridden_ad_setting_from_term($name, Term $term) { } foreach (\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadParents($term->id()) as $parent) { - $override = get_overridden_ad_setting_from_term($name, $parent); + $override = get_overridden_ad_setting_from_term($name, $parent); if (isset($override)) { return $override; } diff --git a/composer.json b/composer.json index 539e851..1bc3dd1 100644 --- a/composer.json +++ b/composer.json @@ -12,5 +12,8 @@ ], "require": { "drupal/breakpoint_js_settings": "8.1.0-rc1" + }, + "require-dev": { + "burdamagazinorg/thunder-dev-tools": "dev-master" } } diff --git a/js/adHelper.js b/js/adHelper.js index b705401..0edd34c 100644 --- a/js/adHelper.js +++ b/js/adHelper.js @@ -1,31 +1,38 @@ +/** + * @file + */ + function getDeviceType() { - "use strict"; - var Breakpoints = window.breakpointSettings.Breakpoints; - var DeviceMapping = window.breakpointSettings.DeviceMapping; + 'use strict'; + + var Breakpoints = window.breakpointSettings.Breakpoints; + var DeviceMapping = window.breakpointSettings.DeviceMapping; - if (window.innerWidth <= Breakpoints[DeviceMapping.tablet]) { - return 'smartphone'; - } + if (window.innerWidth <= Breakpoints[DeviceMapping.tablet]) { + return 'smartphone'; + } - if (window.innerWidth <= Breakpoints[DeviceMapping.desktop]) { - return 'tablet'; - } + if (window.innerWidth <= Breakpoints[DeviceMapping.desktop]) { + return 'tablet'; + } - return 'desktop'; + return 'desktop'; } function deviceIsMobile() { - "use strict"; - return (getDeviceType() === 'smartphone'); + 'use strict'; + + return (getDeviceType() === 'smartphone'); } function deviceIsTablet() { - "use strict"; - return (getDeviceType() === 'tablet'); + 'use strict'; + + return (getDeviceType() === 'tablet'); } function deviceIsDesktop() { - "use strict"; - return (getDeviceType() === 'desktop'); -} + 'use strict'; + return (getDeviceType() === 'desktop'); +} diff --git a/js/adIntegration.js b/js/adIntegration.js index dd36944..886c52d 100644 --- a/js/adIntegration.js +++ b/js/adIntegration.js @@ -1,20 +1,25 @@ -(function ($, Drupal) { +/** + * @file + */ - "use strict"; +(function ($, Drupal) { + 'use strict'; - Drupal.behaviors.place_ads = { - attach: function (context, settings) { - setTags(settings); - } - }; + Drupal.behaviors.place_ads = { + attach: function (context, settings) { + setTags(settings); + } + }; - function setTags(settings){ - if(typeof TFM == "undefined") return; + function setTags(settings) { + if (typeof TFM == 'undefined') { + return; + } - for(var slot_html_id in settings.AdvertisingSlots) { - var tag = settings.AdvertisingSlots[slot_html_id][adsc_device]; - $('#' + slot_html_id).html(''); - } + for (var slot_html_id in settings.AdvertisingSlots) { + var tag = settings.AdvertisingSlots[slot_html_id][adsc_device]; + $('#' + slot_html_id).html(''); } + } })(jQuery, Drupal); diff --git a/src/AdIntegration.php b/src/AdIntegration.php index cee2804..1a25870 100644 --- a/src/AdIntegration.php +++ b/src/AdIntegration.php @@ -1,10 +1,5 @@ token = $token; } - /** - * @inherit + * {@inheritdoc} */ public function getAdUnit1() { return $this->token->replace('[advertising:adsc_unit1]', array(), array('sanitize' => FALSE)); } /** - * @inherit + * {@inheritdoc} */ public function getAdUnit2() { return $this->token->replace('[advertising:adsc_unit2]', array(), array('sanitize' => FALSE)); } /** - * @inherit + * {@inheritdoc} */ public function getAdUnit3() { return $this->token->replace('[advertising:adsc_unit3]', array(), array('sanitize' => FALSE)); } /** - * @inherit + * {@inheritdoc} */ public function getKeyword() { return $this->token->replace('[advertising:adsc_keyword]', array(), array('sanitize' => FALSE)); } /** - * @inherit + * {@inheritdoc} */ public function getAdMode() { return $this->token->replace('[advertising:adsc_mode]', array(), array('sanitize' => FALSE)); } /** - * @inherit + * {@inheritdoc} */ public function getAdProvider() { return $this->settings->get('ad_provider'); } /** - * @inherit + * {@inheritdoc} */ public function getAdEngine() { return $this->settings->get('adsc_ad_engine'); } /** - * @inherit + * {@inheritdoc} */ public function getAdContainerTag() { return $this->settings->get('adsc_container_tag'); @@ -166,5 +165,5 @@ public function getCacheTags() { public function getCacheMaxAge() { return 0; } -} +} diff --git a/src/AdIntegrationInterface.php b/src/AdIntegrationInterface.php index 26627ed..4203d3c 100644 --- a/src/AdIntegrationInterface.php +++ b/src/AdIntegrationInterface.php @@ -1,78 +1,78 @@ t('Ad engine'), '#default_value' => $settings->get('adsc_ad_engine'), ); - + $adsc_unit2_values = $settings->get('adsc_unit2_values'); $form['site_settings']['adsc_unit2_values'] = array( '#type' => 'textarea', '#title' => t('First hierarchy level values'), '#default_value' => !empty($adsc_unit2_values) ? Tags::implode($adsc_unit2_values) : '', - '#description' => t('Comma separated list of possible values for first hierarchy level') + '#description' => t('Comma separated list of possible values for first hierarchy level'), ); $adsc_unit3_values = $settings->get('adsc_unit3_values'); @@ -118,14 +113,14 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'textarea', '#title' => t('Second hierarchy level values'), '#default_value' => !empty($adsc_unit3_values) ? Tags::implode($adsc_unit3_values) : '', - '#description' => t('Comma separated list of possible values for second hierarchy level') + '#description' => t('Comma separated list of possible values for second hierarchy level'), ); $form['default_values']['adsc_unit1_default'] = [ '#title' => t('Ad level 1'), '#type' => 'textfield', '#default_value' => $settings->get('adsc_unit1_default'), - '#description' => t('First hierarchical level. This is the name of the Website') + '#description' => t('First hierarchical level. This is the name of the Website'), ]; $form['default_values']['adsc_unit1_overridable'] = [ @@ -134,18 +129,18 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $settings->get('adsc_unit1_overridable'), ]; - $form['default_values']['adsc_unit2_default'] = [ '#title' => t('Ad level 2'), '#default_value' => $settings->get('adsc_unit2_default'), - '#description' => t('Second hierarchical level') + '#description' => t('Second hierarchical level'), ]; - if(empty($adsc_unit2_values)) { + if (empty($adsc_unit2_values)) { $form['default_values']['adsc_unit2_default']['#type'] = 'textfield'; - } else { + } + else { $form['default_values']['adsc_unit2_default']['#type'] = 'select'; - $form['default_values']['adsc_unit2_default']['#options'] = array_combine($adsc_unit2_values, $adsc_unit2_values); + $form['default_values']['adsc_unit2_default']['#options'] = array_combine($adsc_unit2_values, $adsc_unit2_values); } $form['default_values']['adsc_unit2_overridable'] = [ @@ -157,14 +152,15 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['default_values']['adsc_unit3_default'] = [ '#title' => t('Ad level 3'), '#default_value' => $settings->get('adsc_unit3_default'), - '#description' => t('Third hierarchical level') + '#description' => t('Third hierarchical level'), ]; - if(empty($adsc_unit3_values)) { + if (empty($adsc_unit3_values)) { $form['default_values']['adsc_unit3_default']['#type'] = 'textfield'; - } else { + } + else { $form['default_values']['adsc_unit3_default']['#type'] = 'select'; - $form['default_values']['adsc_unit3_default']['#options'] = array_combine($adsc_unit3_values, $adsc_unit3_values); + $form['default_values']['adsc_unit3_default']['#options'] = array_combine($adsc_unit3_values, $adsc_unit3_values); } $form['default_values']['adsc_unit3_overridable'] = [ @@ -202,7 +198,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); $values = $form_state->getValues(); - $config =$this->configFactory()->getEditable('ad_integration.settings'); + $config = $this->configFactory()->getEditable('ad_integration.settings'); $config->set('adsc_container_tag', $values['adsc_container_tag']) ->set('adsc_ad_engine', $values['adsc_ad_engine']) ->set('ad_provider', $values['ad_provider']) @@ -219,7 +215,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ->save(); } - /** * {@inheritdoc} */ @@ -228,4 +223,5 @@ protected function getEditableConfigNames() { 'ad_integration.settings', ]; } + } diff --git a/src/Plugin/Block/AdvertisingSlot.php b/src/Plugin/Block/AdvertisingSlot.php index 36f4382..f433621 100644 --- a/src/Plugin/Block/AdvertisingSlot.php +++ b/src/Plugin/Block/AdvertisingSlot.php @@ -2,6 +2,7 @@ namespace Drupal\ad_integration\Plugin\Block; +use Drupal\Core\Cache\Cache; use Drupal\ad_integration\AdIntegrationInterface; use Drupal\Component\Utility\Crypt; use Drupal\Core\Block\BlockBase; @@ -77,7 +78,7 @@ public static function create( */ public function defaultConfiguration() { return [ - 'adtype' => 'iframe' + 'adtype' => 'iframe', ]; } @@ -88,7 +89,7 @@ public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); $config = $this->getConfiguration(); - /** + /* * TODO: turn textfield into select list from configurable ad tags */ if ($mappings = $this->getDeviceMappings()) { @@ -114,7 +115,7 @@ public function blockForm($form, FormStateInterface $form_state) { '#title' => $this->t('Ad type'), '#required' => TRUE, '#default_value' => $config['adtype'] ? $config['adtype'] : 'iframe', - '#options' => array('inline' => $this->t('Inline'), 'iframe' => $this->t('IFrame')) + '#options' => array('inline' => $this->t('Inline'), 'iframe' => $this->t('IFrame')), ]; return $form; } @@ -136,6 +137,9 @@ public function blockSubmit($form, FormStateInterface $form_state) { $this->setConfigurationValue('adtype', $form_state->getValue('adtype')); } + /** + * {@inheritdoc} + */ public function build() { $config = $this->getConfiguration(); $html_id = 'ad-slot--' . Crypt::randomBytesBase64(8); @@ -148,8 +152,8 @@ public function build() { '#cache' => [ 'contexts' => ['url.path'], 'tags' => $this->adIntegration->getCacheTags(), - 'max-age' => \Drupal\Core\Cache\Cache::PERMANENT - ] + 'max-age' => Cache::PERMANENT, + ], ]; $attachments = [$html_id => []]; @@ -172,6 +176,12 @@ public function build() { return $render; } + /** + * Get Device Mappings. + * + * @return mixed + * Returns mappings, if not found returns FALSE. + */ private function getDeviceMappings() { if ($config = $this->configFactory->get('breakpoint_js_settings.settings')) { if ($mappings = $config->get('device_mappings')) { @@ -180,4 +190,5 @@ private function getDeviceMappings() { } return FALSE; } + } diff --git a/src/Plugin/Field/FieldFormatter/AdEmptyFormatter.php b/src/Plugin/Field/FieldFormatter/AdEmptyFormatter.php index 8e89ab3..aa42de8 100644 --- a/src/Plugin/Field/FieldFormatter/AdEmptyFormatter.php +++ b/src/Plugin/Field/FieldFormatter/AdEmptyFormatter.php @@ -1,10 +1,5 @@ configFactory->get('ad_integration.settings'); $settingsForm = $this->formBuilder->getForm('\Drupal\ad_integration\Form\SettingsForm'); - // add configurable settings - foreach(Element::children($settingsForm['default_values']) as $child_element){ - if(strrpos($child_element, '_overridable') !== FALSE && ($settings->get($child_element) == 1)) { + // Add configurable settings. + foreach (Element::children($settingsForm['default_values']) as $child_element) { + if (strrpos($child_element, '_overridable') !== FALSE && ($settings->get($child_element) == 1)) { $value_element_name = str_replace('_overridable', '', $child_element); $default_value_element_name = $value_element_name . '_default'; $default_value_element = $settingsForm['default_values'][$default_value_element_name]; @@ -104,13 +99,14 @@ public function formElement( $element[$value_element_name]['#default_value'] = isset($items[$delta]->$value_element_name) ? $items[$delta]->$value_element_name : NULL; $element[$value_element_name]['#required'] = FALSE; - if(!empty($default_value_element['#options'])) { + if (!empty($default_value_element['#options'])) { $element[$value_element_name]['#options'] = $default_value_element['#options']; $element[$value_element_name]['#empty_option'] = t('Site default value'); } } } - // add keywords + + // Add keywords. $value_element_name = 'adsc_keyword'; $element[$value_element_name]['#type'] = 'textfield'; $element[$value_element_name]['#title'] = t('Keywords'); @@ -120,4 +116,5 @@ public function formElement( return $element; } + }