diff --git a/README.txt b/README.txt index 91da474..3b2eea4 100644 --- a/README.txt +++ b/README.txt @@ -99,4 +99,4 @@ Current maintainers: This project has been sponsored by: * Elevated Third - Empowering B2B marketing ecosystems with strategic thinking, top-notch user experience design and world-class Drupal development. \ No newline at end of file + Empowering B2B marketing ecosystems with strategic thinking, top-notch user experience design and world-class Drupal development. diff --git a/css/form.css b/css/form.css index 76d03b3..69ed240 100644 --- a/css/form.css +++ b/css/form.css @@ -212,4 +212,4 @@ background-color: #f5f5f2; border: 1px solid #e3e3e3; margin-top: 10px; -} \ No newline at end of file +} diff --git a/js/condition.common.js b/js/condition.common.js index 5ff010d..067c865 100644 --- a/js/condition.common.js +++ b/js/condition.common.js @@ -8,32 +8,32 @@ if (Field.pluginId == 'group') { var condition_is_appeased = true; Field.appeased = Field.appeased || false; - if(Field.appeased) { + if (Field.appeased) { return true; } for (var i = 0; i < Field.conditions.length; i++) { var Condition = Field.conditions[i]; SmartContentManager.invoke('Field', 'initCheckAppeased', Condition.field); - if(!Condition.appeased && Condition.field.processed) { + if (!Condition.appeased && Condition.field.processed) { Condition.appeased = true; } - if(!Condition.appeased) { + if (!Condition.appeased) { condition_is_appeased = false; } } - if(condition_is_appeased) { + if (condition_is_appeased) { Field.appeased = true; Field.complete(Field.conditions); } } }, init: function (Field) { - if(Field.pluginId == 'true') { + if (Field.pluginId == 'true') { Field.claim(); Field.complete(true); } - else if(Field.pluginId == 'group') { + else if (Field.pluginId == 'group') { Field.claim(); for (var i = 0; i < Field.conditions.length; i++) { Field.conditions[i] = new Drupal.smart_content.model.Condition(Field.conditions[i]); @@ -41,7 +41,7 @@ Field.conditions[i].field = field; } } - else if(Field.pluginId == 'broken') { + else if (Field.pluginId == 'broken') { Field.claim(); Field.complete(false); } @@ -52,31 +52,31 @@ SmartContentManager.condition_type['plugin:group'].ConditionGroup = { evaluate: function (values, context) { var result = false; - if(values.op == 'AND') { + if (values.op == 'AND') { result = true; for (var i = 0; i < context.length; i++) { context[i].evaluateClientside(); - if(!context[i].result) { + if (!context[i].result) { result = false; } } } - if(values.op == 'OR') { + if (values.op == 'OR') { for (var i = 0; i < context.length; i++) { context[i].evaluateClientside(); - if(context[i].result) { + if (context[i].result) { result = true; } } } return result; } - } + }; SmartContentManager.condition_type['plugin:broken'] = SmartContentManager.condition_type['plugin:broken'] || {}; - SmartContentManager.condition_type['plugin:broken'].ConditionBroken= { + SmartContentManager.condition_type['plugin:broken'].ConditionBroken = { evaluate: function (values, context) { return context; } } -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/js/condition_type.standard.js b/js/condition_type.standard.js index f630ff7..41fb84a 100644 --- a/js/condition_type.standard.js +++ b/js/condition_type.standard.js @@ -70,9 +70,9 @@ SmartContentManager.condition_type['type:value'] = SmartContentManager.condition_type['type:value'] || {}; SmartContentManager.condition_type['type:value'].ConditionTypeStandard = { evaluate: function (values, context) { - return context; + return context; } - } + }; SmartContentManager.condition_type['type:select'] = SmartContentManager.condition_type['type:select'] || {}; SmartContentManager.condition_type['type:select'].ConditionTypeStandard = { diff --git a/js/decision.client.js b/js/decision.client.js index 93ab5c3..b9ae465 100644 --- a/js/decision.client.js +++ b/js/decision.client.js @@ -24,16 +24,17 @@ var Variation = Decision.variations[i]; // If not appeased, loop through conditions and check process status. - if(!Variation.appeased) { + if (!Variation.appeased) { Variation.checkAppeased(); } - // If after processing conditions, variation still not appeased, restrict later variants from processing Decision. - if(!Variation.appeased) { + // If after processing conditions, variation still not appeased, + // restrict later variants from processing Decision. + if (!Variation.appeased) { var earlier_variation_not_appeased = true; } // Process variation if previous Variations appeased and evaluate false. - if(Variation.appeased && !Variation.processed && !earlier_variation_not_appeased) { + if (Variation.appeased && !Variation.processed && !earlier_variation_not_appeased) { Variation.processed = true; // Evaluate condition @@ -42,14 +43,15 @@ // Initialize variable for broadcast after a winner is selected. let winner = null; // Variation.result = Boolean(Math.round(Math.random())); - if(Variation.result) { + if (Variation.result) { Decision.processed = true; Decision.params = [Decision.name.split(/\.(.+)/)[0], Decision.name.split(/\.(.+)/)[1], Variation.id]; winner = Variation; - } else { - if(i == (Decision.variations.length - 1)) { + } + else { + if (i == (Decision.variations.length - 1)) { Decision.processed = true; - if(Decision.default_variation) { + if (Decision.default_variation) { Decision.params = [Decision.name.split(/\.(.+)/)[0], Decision.name.split(/\.(.+)/)[1], Decision.default_variation]; winner = Variation; } @@ -60,11 +62,14 @@ } }, execute: function (Decision) { - if(Decision.params.length === 3) { + if (Decision.params.length === 3) { var url = '/ajax/smart-content/decision/' + Decision.params.join('/'); - if(Decision.context.length !== 0) { - var query = Object.keys(Decision.context).reduce(function(a,k){a.push(k+'='+encodeURIComponent(Decision.context[k]));return a},[]).join('&') + if (Decision.context.length !== 0) { + var query = Object.keys(Decision.context).reduce(function (a, k) { + a.push(k + '=' + encodeURIComponent(Decision.context[k])); + return a + }, []).join('&'); var url = url + '?' + query; } var ajaxObject = new Drupal.ajax({ @@ -96,4 +101,4 @@ Condition.result = false; } } -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/js/decision.js b/js/decision.js index f1dc16d..a2fc56f 100644 --- a/js/decision.js +++ b/js/decision.js @@ -10,10 +10,10 @@ Drupal.smart_content = {}; Drupal.smart_content.model = {}; - SmartContentManager.invoke = function(type, hook, object) { - if(typeof SmartContentManager.plugin[type] !== 'undefined') { + SmartContentManager.invoke = function (type, hook, object) { + if (typeof SmartContentManager.plugin[type] !== 'undefined') { for (var name in SmartContentManager.plugin[type]) { - if(typeof SmartContentManager.plugin[type][name][hook] === "function") { + if (typeof SmartContentManager.plugin[type][name][hook] === "function") { SmartContentManager.plugin[type][name][hook](object); } } @@ -22,7 +22,7 @@ SmartContentManager.getField = function (pluginId) { for (var i = 0; i < SmartContentManager.instance.fields.length; i++) { - if(SmartContentManager.instance.fields[i].pluginId == pluginId) { + if (SmartContentManager.instance.fields[i].pluginId == pluginId) { return SmartContentManager.instance.fields[i]; } } @@ -31,13 +31,13 @@ SmartContentManager.addFieldData = function (field_data, skip_check) { field_data.unique = field_data.unique || false; var field; - if(skip_check === true || field_data.unique || field_data.unique == 'true') { + if (skip_check === true || field_data.unique || field_data.unique == 'true') { field = new Field(field_data); SmartContentManager.addField(field); } else { field = SmartContentManager.getField(field_data.pluginId); - if(typeof field === 'undefined') { + if (typeof field === 'undefined') { field = new Field(field_data); SmartContentManager.addField(field); } @@ -51,22 +51,24 @@ SmartContentManager.getDecision = function (name) { for (var i = 0; i < SmartContentManager.instance.decisions.length; i++) { - if(SmartContentManager.instance.decisions[i].name == name) { + if (SmartContentManager.instance.decisions[i].name == name) { return SmartContentManager.instance.decisions[i]; } } }; - SmartContentManager.attach = function(data_attribute, context) { + SmartContentManager.attach = function (data_attribute, context) { $('[' + data_attribute + ']', context).once('ajax-build').each(function (i, el) { var id = $(this).attr(data_attribute); if (typeof drupalSettings.smartContentDecisions !== 'undefined') { for (var d in drupalSettings.smartContentDecisions) { if (drupalSettings.smartContentDecisions[d].name == id) { - var a = [].filter.call(this.attributes, function(at) { return /^data-context-/.test(at.name); }) + var a = [].filter.call(this.attributes, function (at) { + return /^data-context-/.test(at.name); + }); var context = {}; - Object.keys(a).forEach(function(key) { - context[a[key].name.replace(/^(data-context-)/,"")] = a[key].value; - }) + Object.keys(a).forEach(function (key) { + context[a[key].name.replace(/^(data-context-)/, "")] = a[key].value; + }); drupalSettings.smartContentDecisions[d].context = context; drupalSettings.smartContentDecisions[d].default_variation = this.getAttribute('data-default-id'); Drupal.smart_content.SmartContentManager.init(drupalSettings.smartContentDecisions[d]); @@ -83,7 +85,7 @@ }; SmartContentManager.init = function (settings) { - if(!SmartContentManager.getDecision(settings.name)) { + if (!SmartContentManager.getDecision(settings.name)) { var decision = new Decision(settings); for (var i = 0; i < decision.variations.length; i++) { decision.variations[i] = new Variation(decision.variations[i]); @@ -95,13 +97,14 @@ } SmartContentManager.addDecision(decision); decision.process(); - } else { + } + else { //@todo: allow for previous made decisions to be reused. } }; SmartContentManager.queueProcessAll = function (status) { - if(typeof status === 'undefined') { + if (typeof status === 'undefined') { status = true; } SmartContentManager.needs_processing = status; @@ -111,7 +114,7 @@ for (var i = 0; i < SmartContentManager.instance.decisions.length; i++) { SmartContentManager.instance.decisions[i].process(); } - if(SmartContentManager.needs_processing) { + if (SmartContentManager.needs_processing) { SmartContentManager.queueProcessAll(false); SmartContentManager.processAll(); } @@ -133,7 +136,7 @@ Decision.prototype.process = function () { SmartContentManager.invoke('Decision', 'process', this); SmartContentManager.invoke(this.agent, 'process', this); - if(this.processed && !this.executed) { + if (this.processed && !this.executed) { this.execute(); } }; @@ -161,11 +164,11 @@ for (var ii = 0; ii < this.conditions.length; ii++) { var Condition = this.conditions[ii]; SmartContentManager.invoke('Field', 'initCheckAppeased', Condition.field); - if(!Condition.appeased && Condition.field.processed) { + if (!Condition.appeased && Condition.field.processed) { Condition.appeased = true; } // If still not appeassed, keep Variation appeased set to false. - if(!Condition.appeased) { + if (!Condition.appeased) { variation_is_appeased = false; } } @@ -176,7 +179,7 @@ var result = true; for (var ii = 0; ii < this.conditions.length; ii++) { this.conditions[ii].evaluateClientside(); - if(!this.conditions[ii].result) { + if (!this.conditions[ii].result) { result = false; } } @@ -198,24 +201,25 @@ this.result = false; //@todo: determine if this needs to be alterable - if(typeof SmartContentManager.condition_type[this.field.type] !== 'undefined' + if (typeof SmartContentManager.condition_type[this.field.type] !== 'undefined' && typeof this.settings !== 'undefined' ) { - for (var name in SmartContentManager.condition_type[this.field.type]) { - if(typeof SmartContentManager.condition_type[this.field.type][name].evaluate === 'function') { - var result = SmartContentManager.condition_type[this.field.type][name].evaluate(this.settings, this.field.context); - //@todo: standardize negate type. - if(this.settings.negate === true || this.settings.negate === '1' || this.settings.negate === 1) { - this.result = !result; - } else { - this.result = result; - } - if(this.result) { - return; - } + for (var name in SmartContentManager.condition_type[this.field.type]) { + if (typeof SmartContentManager.condition_type[this.field.type][name].evaluate === 'function') { + var result = SmartContentManager.condition_type[this.field.type][name].evaluate(this.settings, this.field.context); + //@todo: standardize negate type. + if (this.settings.negate === true || this.settings.negate === '1' || this.settings.negate === 1) { + this.result = !result; + } + else { + this.result = result; + } + if (this.result) { + return; } } } + } else { } @@ -232,7 +236,7 @@ }; $.extend(this, defaults, settings); SmartContentManager.invoke('Field', 'init', this); - if(!this.claimed) { + if (!this.claimed) { this.claim(); this.complete(); } @@ -246,7 +250,7 @@ Field.prototype.complete = function (context, force_processing) { this.processed = true; this.context = context; - if(typeof force_processing !== 'undefined' && force_processing) { + if (typeof force_processing !== 'undefined' && force_processing) { SmartContentManager.processAll(); } else { @@ -258,9 +262,6 @@ Drupal.smart_content.model.Field = Field; - - - // // Drupal.smart_content.model.Decision = function (name, agent) { // this.name = name; @@ -268,11 +269,8 @@ // this.variations = []; // } // - // Drupal.smart_content.model.Decision.prototype.setVariation = function (id, override) { - // if(typeof override == undefined) { - // override = false; - // } - // } + // Drupal.smart_content.model.Decision.prototype.setVariation = function (id, + // override) { if(typeof override == undefined) { override = false; } } // @@ -281,80 +279,31 @@ // attach: function (context, settings) { // // @todo: move all of this to individual decisions // var found = false; - // $('[data-smart-content-decision]', context).once('ajax-build').each(function () { - // found = true; - // var $wrapper = $(this); - // Drupal.SmartDecisionManager.addDecision($wrapper.attr('data-smart-content-decision')); - // }); - // if(found) { - // Drupal.SmartDecisionManager.execute(); - // } - // } - // } - // - // - // Drupal.SmartDecisionManager = {} - // Drupal.smart_content = Drupal.smart_content || {}; - // Drupal.smart_content.decisions = Drupal.smart_content.decisions || []; - // + // $('[data-smart-content-decision]', + // context).once('ajax-build').each(function () { found = true; var $wrapper + // = $(this); + // Drupal.SmartDecisionManager.addDecision($wrapper.attr('data-smart-content-decision')); + // }); if(found) { Drupal.SmartDecisionManager.execute(); } } } + // Drupal.SmartDecisionManager = {} Drupal.smart_content = + // Drupal.smart_content || {}; Drupal.smart_content.decisions = + // Drupal.smart_content.decisions || []; // Drupal.SmartDecisionManager.addDecision = function (id) { - // if(Drupal.smart_content.decisions.indexOf(id) < 0) { - // Drupal.smart_content.decisions.push(id); - // } - // } - // - // Drupal.SmartDecisionManager.execute = function () { - // var decisions = Drupal.smart_content.decisions; - // for (d=0; d < decisions.length;d++) { - // var entity_id = decisions[d].split(/\.(.+)/)[1]; - // var query = {data: {'condition_default:browser.language' : 'en', test2 : 'testttyeah'}}; - // var url = '/ajax/smart-content/decision/config/' + entity_id; - // var ajaxObject = new Drupal.ajax({ - // url: url, - // progress: false, - // success: function (response, status) { - // for (var i in response) { - // if (response.hasOwnProperty(i) && response[i].command && this.commands[response[i].command]) { - // this.commands[response[i].command](this, response[i], status); - // } - // } - // } - // }); - // ajaxObject.options.data['context'] = $.param(query); - // - // ajaxObject.execute(); - // } - // } - + // if(Drupal.smart_content.decisions.indexOf(id) < 0) { + // Drupal.smart_content.decisions.push(id); } } Drupal.SmartDecisionManager.execute = function () { var decisions = Drupal.smart_content.decisions; for (d=0; d < decisions.length;d++) { var entity_id = decisions[d].split(/\.(.+)/)[1]; var query = {data: {'condition_default:browser.language' : 'en', test2 : 'testttyeah'}}; var url = '/ajax/smart-content/decision/config/' + entity_id; var ajaxObject = new Drupal.ajax({ url: url, progress: false, success: function (response, status) { for (var i in response) { if (response.hasOwnProperty(i) && response[i].command && this.commands[response[i].command]) { this.commands[response[i].command](this, response[i], status); } } } }); ajaxObject.options.data['context'] = $.param(query); ajaxObject.execute(); } } // Drupal.SmartDecisionManager = function () { - // this.decisions = (typeof this.decisions === 'undefined') ? [] : this.decisions; - // } - // Drupal.SmartDecisionManager.prototype = { - // - // /** - // * Command to insert new content into the DOM. - // * - // * @param {Drupal.Ajax} ajax - // * {@link Drupal.Ajax} object created by {@link Drupal.ajax}. - // * @param {object} response - // * The response from the Ajax request. - // * @param {string} response.data - // * The data to use with the jQuery method. - // * @param {string} [response.method] - // * The jQuery DOM manipulation method to be used. - // * @param {string} [response.selector] - // * A optional jQuery selector string. - // * @param {object} [response.settings] - // * An optional array of settings that will be used. - // * @param {number} [status] - // * The XMLHttpRequest status. - // */ - // addDecision: function (id) { - // - // } - // } + // this.decisions = (typeof this.decisions === 'undefined') ? [] : + // this.decisions; } Drupal.SmartDecisionManager.prototype = { /** * Command + // to insert new content into the DOM. * * @param {Drupal.Ajax} ajax * + // {@link Drupal.Ajax} object created by {@link Drupal.ajax}. * @param + // {object} response * The response from the Ajax request. * @param + // {string} response.data * The data to use with the jQuery method. * + // @param {string} [response.method] * The jQuery DOM manipulation method + // to be used. * @param {string} [response.selector] * A optional jQuery + // selector string. * @param {object} [response.settings] * An optional + // array of settings that will be used. * @param {number} [status] * The + // XMLHttpRequest status. */ addDecision: function (id) { } } Drupal.smart_content.SmartContentManager = SmartContentManager; @@ -411,4 +360,4 @@ // fallback: {} // } // ] -// ] \ No newline at end of file +// ] diff --git a/js/form.js b/js/form.js index 7a391c8..fd354cf 100644 --- a/js/form.js +++ b/js/form.js @@ -1,20 +1,21 @@ (function ($) { - Drupal.behaviors.form = { - attach: function (context, settings) { - var checkbox = $('.variations-container [class^=smart-variations-default-]', context); - checkbox.change(function () { - if ($(this).is(':checked')) { - $(checkbox).each(function () { - if (!$(this).is(':checked')) { - $(this).attr('disabled', true); - } - }); - } else { - $(checkbox).each(function () { - $(this).attr('disabled', false); - }); - } - }); - } + Drupal.behaviors.form = { + attach: function (context, settings) { + var checkbox = $('.variations-container [class^=smart-variations-default-]', context); + checkbox.change(function () { + if ($(this).is(':checked')) { + $(checkbox).each(function () { + if (!$(this).is(':checked')) { + $(this).attr('disabled', true); + } + }); + } + else { + $(checkbox).each(function () { + $(this).attr('disabled', false); + }); + } + }); } -})(jQuery); \ No newline at end of file + } +})(jQuery); diff --git a/modules/smart_content_block/smart_content_block.install b/modules/smart_content_block/smart_content_block.install index 9cbfcda..4b29093 100644 --- a/modules/smart_content_block/smart_content_block.install +++ b/modules/smart_content_block/smart_content_block.install @@ -1,12 +1,15 @@ execute(); - foreach($ids as $id) { + foreach ($ids as $id) { $updated = FALSE; /** @var \Drupal\Core\Config\ImmutableConfig $config */ $config = \Drupal::service('config.factory') diff --git a/modules/smart_content_block/src/Plugin/Block/SmartBlock.php b/modules/smart_content_block/src/Plugin/Block/SmartBlock.php index e899f1c..3512ca4 100644 --- a/modules/smart_content_block/src/Plugin/Block/SmartBlock.php +++ b/modules/smart_content_block/src/Plugin/Block/SmartBlock.php @@ -24,7 +24,7 @@ class SmartBlock extends BlockBase { */ public function defaultConfiguration() { return [ - 'variation_set' => null, + 'variation_set' => NULL, ]; } @@ -96,11 +96,14 @@ class SmartBlock extends BlockBase { // Set the entity ID value. $element['variation_set'] = [ '#type' => 'value', - '#value' => $entity->id() + '#value' => $entity->id(), ]; return $element; } + /** + * + */ public function blockValidate($form, FormStateInterface $form_state) { parent::blockValidate($form, $form_state); if ($form_state instanceof SubformStateInterface) { @@ -126,8 +129,8 @@ class SmartBlock extends BlockBase { } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function blockSubmit($form, FormStateInterface $form_state) { if ($form_state instanceof SubformStateInterface) { $parent_form = $form_state->getCompleteForm(); @@ -140,7 +143,7 @@ class SmartBlock extends BlockBase { $parents = isset($form['#form_id']) && $form['#form_id'] == 'block_form' ? ['settings'] : $form['#array_parents']; $parents[] = 'variation_set_config'; - if (!$variation_set_form = NestedArray::getValue($parent_form, $parents)) { + if (!$variation_set_form = NestedArray::getValue($parent_form, $parents)) { $variation_set_form = []; } $variation_set_form_state = SubformState::createForSubform($variation_set_form, $parent_form, $parent_form_state); diff --git a/modules/smart_content_block/src/Plugin/smart_content/Reaction/Block.php b/modules/smart_content_block/src/Plugin/smart_content/Reaction/Block.php index 4d62664..defada8 100644 --- a/modules/smart_content_block/src/Plugin/smart_content/Reaction/Block.php +++ b/modules/smart_content_block/src/Plugin/smart_content/Reaction/Block.php @@ -5,10 +5,6 @@ namespace Drupal\smart_content_block\Plugin\smart_content\Reaction; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Form\SubformState; -use Drupal\smart_content\Annotation\SmartReaction; -use Drupal\smart_content\Form\SmartVariationSetForm; -use Drupal\smart_content\Reaction\ReactionBase; use Drupal\smart_content\Reaction\ReactionConfigurableBase; /** @@ -73,7 +69,7 @@ class Block extends ReactionConfigurableBase { else { $form['block_instance']['id'] = [ '#type' => 'select', - // '#title' => $this->t('Block'), + // '#title' => $this->t('Block'),. '#title' => 'Block', '#title_display' => 'invisible', '#options' => $options, @@ -94,10 +90,12 @@ class Block extends ReactionConfigurableBase { return $form; } + /** + * + */ public function getBlock() { $configuration = $this->getConfiguration(); - if (empty($configuration['block_instance']['id'])) { return NULL; } @@ -106,7 +104,6 @@ class Block extends ReactionConfigurableBase { } $block_configuration = isset($configuration['block_instance']) ? $configuration['block_instance'] : []; - if (!isset($this->blockInstance)) { /** @var \Drupal\Core\Block\BlockManagerInterface $block_manager */ $block_manager = \Drupal::service('plugin.manager.block'); @@ -135,7 +132,6 @@ class Block extends ReactionConfigurableBase { return $this->blockInstance; } - /** * Ajax callback that return block configuration setting form. */ @@ -151,12 +147,18 @@ class Block extends ReactionConfigurableBase { $form_state->setRebuild(); } + /** + * + */ public function refreshElementBlock(array $form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1)); } - function getResponseContent() { + /** + * + */ + public function getResponseContent() { $block_instance = $this->getBlock(); // Make sure the block exists and is accessible. @@ -177,9 +179,9 @@ class Block extends ReactionConfigurableBase { 'content' => $block_instance->build(), ]; - // /** @var \Drupal\Core\Render\RendererInterface $renderer */ + // /** @var \Drupal\Core\Render\RendererInterface $renderer */ // $renderer = \Drupal::service('renderer'); - // $renderer->addCacheableDependency($elements[$delta], $block_instance); + // $renderer->addCacheableDependency($elements[$delta], $block_instance);. } /** diff --git a/modules/smart_content_block/src/Plugin/smart_content/Variation/VariationBlock.php b/modules/smart_content_block/src/Plugin/smart_content/Variation/VariationBlock.php index 873ecef..a0a983f 100644 --- a/modules/smart_content_block/src/Plugin/smart_content/Variation/VariationBlock.php +++ b/modules/smart_content_block/src/Plugin/smart_content/Variation/VariationBlock.php @@ -153,7 +153,6 @@ class VariationBlock extends VariationBase { $form['reactions_config']['reaction_items'][$reaction_id]['plugin_form']['#attributes']['class'][] = 'reaction'; $form['reactions_config']['reaction_items'][$reaction_id]['#weight'] = $reaction->getWeight(); - $form['reactions_config']['reaction_items'][$reaction_id]['#attributes']['class'][] = 'draggable'; $form['reactions_config']['reaction_items'][$reaction_id]['#attributes']['class'][] = 'row-reaction'; @@ -165,7 +164,6 @@ class VariationBlock extends VariationBase { '#attributes' => ['class' => [$wrapper_items_id . '-order-reaction-weight']], ]; - $form['reactions_config']['reaction_items'][$reaction_id]['remove_reaction'] = [ '#type' => 'submit', '#value' => t('Remove Reaction'), @@ -190,7 +188,6 @@ class VariationBlock extends VariationBase { '#type' => 'container', ]; - $form['reactions_config']['add_reaction'] = [ '#type' => 'container', '#title' => 'Add Reaction', @@ -276,6 +273,9 @@ class VariationBlock extends VariationBase { } } + /** + * + */ public function addElementConditionValidate(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); $parents = array_slice($button['#parents'], 0, -1); @@ -285,6 +285,9 @@ class VariationBlock extends VariationBase { } } + /** + * + */ public function addElementCondition(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); // Save condition weight. @@ -298,12 +301,18 @@ class VariationBlock extends VariationBase { $form_state->setRebuild(); } + /** + * + */ public function addElementConditionAjax(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); // Go one level up in the form, to the widgets container. return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2)); } + /** + * + */ public function removeElementCondition(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); @@ -322,14 +331,20 @@ class VariationBlock extends VariationBase { } + /** + * + */ public function removeElementConditionAjax(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); // Go one level up in the form, to the widgets container. return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -3)); } + /** + * + */ public function addElementReaction(array &$form, FormStateInterface $form_state) { - //@todo: reorder reactions to account for drupal core issue. + // @todo: reorder reactions to account for drupal core issue. $button = $form_state->getTriggeringElement(); // Save reaction weight. @@ -342,13 +357,18 @@ class VariationBlock extends VariationBase { $form_state->setRebuild(); } - + /** + * + */ public function addElementReactionAjax(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); // Go one level up in the form, to the widgets container. return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2)); } + /** + * + */ public function removeElementReaction(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); @@ -367,9 +387,13 @@ class VariationBlock extends VariationBase { } + /** + * + */ public function removeElementReactionAjax(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); // Go one level up in the form, to the widgets container. return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -3)); } + } diff --git a/modules/smart_content_block/src/Plugin/smart_content/VariationSetType/Block.php b/modules/smart_content_block/src/Plugin/smart_content/VariationSetType/Block.php index aaba8b2..b81e9fa 100644 --- a/modules/smart_content_block/src/Plugin/smart_content/VariationSetType/Block.php +++ b/modules/smart_content_block/src/Plugin/smart_content/VariationSetType/Block.php @@ -117,7 +117,6 @@ class Block extends VariationSetTypeBase { ], ]; - return $form; } @@ -151,7 +150,9 @@ class Block extends VariationSetTypeBase { $this->attachFormValues($form_state->getValues()['variations_config']['variation_items']); } - + /** + * + */ public function attachFormValues($values) { foreach ($this->entity->getVariations() as $variation) { // Attaching default_variation value to variation config. @@ -168,6 +169,9 @@ class Block extends VariationSetTypeBase { } } + /** + * + */ public function addElementVariation(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); $items = array_slice($button['#parents'], 0, -1); @@ -178,12 +182,18 @@ class Block extends VariationSetTypeBase { $form_state->setRebuild(); } + /** + * + */ public function addElementVariationAjax(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); // Go one level up in the form, to the widgets container. return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1)); } + /** + * + */ public function removeElementVariation(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); $items = array_slice($button['#parents'], 0, -3); @@ -195,9 +205,13 @@ class Block extends VariationSetTypeBase { $form_state->setRebuild(); } + /** + * + */ public function removeElementVariationAjax(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); // Go one level up in the form, to the widgets container. return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -3)); } + } diff --git a/modules/smart_content_block/templates/smart-content-block.html.twig b/modules/smart_content_block/templates/smart-content-block.html.twig index ac18150..5a434ac 100644 --- a/modules/smart_content_block/templates/smart-content-block.html.twig +++ b/modules/smart_content_block/templates/smart-content-block.html.twig @@ -1,3 +1,3 @@ {% block content %} - {{ content }} - {% endblock %} + {{ content }} +{% endblock %} diff --git a/modules/smart_content_browser/js/condition.browser.js b/modules/smart_content_browser/js/condition.browser.js index f5ae992..a7d2776 100644 --- a/modules/smart_content_browser/js/condition.browser.js +++ b/modules/smart_content_browser/js/condition.browser.js @@ -4,19 +4,19 @@ Drupal.smart_content.SmartContentManager.plugin.Field = Drupal.smart_content.SmartContentManager.plugin.Field || {}; Drupal.smart_content.SmartContentManager.plugin.Field.browserSmartCondition = { init: function (Field) { - if(Field.pluginId == 'browser:language') { + if (Field.pluginId == 'browser:language') { Field.claim(); var language = window.navigator.userLanguage || window.navigator.language; Field.complete(language); } - else if(Field.pluginId == 'browser:mobile') { + else if (Field.pluginId == 'browser:mobile') { Field.claim(); var mobile = Boolean((typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1)); Field.complete(mobile); } - else if(Field.pluginId == 'browser:platform_os') { + else if (Field.pluginId == 'browser:platform_os') { Field.claim(); var platform = window.navigator.platform; var ua = window.navigator.userAgent; @@ -52,20 +52,20 @@ Field.complete(os); } - else if(Field.pluginId == 'browser:cookie_enabled') { + else if (Field.pluginId == 'browser:cookie_enabled') { Field.claim(); Field.complete(navigator.cookieEnabled); } - else if(Field.pluginId == 'browser:cookie') { + else if (Field.pluginId == 'browser:cookie') { Field.claim(); cookie_value = $.cookie(Field.settings.key); Field.complete(cookie_value); } - else if(Field.pluginId == 'browser:localstorage') { + else if (Field.pluginId == 'browser:localstorage') { Field.claim(); Field.complete(localStorage[Field.settings.key]); } - else if(Field.pluginId == 'browser:width') { + else if (Field.pluginId == 'browser:width') { Field.claim(); Field.complete(Math.max( document.body.scrollWidth, @@ -75,7 +75,7 @@ document.documentElement.clientWidth )); } - else if(Field.pluginId == 'browser:height') { + else if (Field.pluginId == 'browser:height') { Field.claim(); Field.complete(Math.max( document.body.scrollHeight, @@ -87,4 +87,4 @@ } } } -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/modules/smart_content_browser/src/Plugin/Derivative/BrowserDerivative.php b/modules/smart_content_browser/src/Plugin/Derivative/BrowserDerivative.php index 90fa1b0..23356da 100644 --- a/modules/smart_content_browser/src/Plugin/Derivative/BrowserDerivative.php +++ b/modules/smart_content_browser/src/Plugin/Derivative/BrowserDerivative.php @@ -4,6 +4,9 @@ namespace Drupal\smart_content_browser\Plugin\Derivative; use Drupal\Component\Plugin\Derivative\DeriverBase; +/** + * + */ class BrowserDerivative extends DeriverBase { /** @@ -12,47 +15,47 @@ class BrowserDerivative extends DeriverBase { public function getDerivativeDefinitions($base_plugin_definition) { $this->derivatives = [ 'language' => [ - 'label' => 'Language', - 'type' => 'textfield', - ] + $base_plugin_definition, + 'label' => 'Language', + 'type' => 'textfield', + ] + $base_plugin_definition, 'mobile' => [ - 'label' => 'Mobile', - 'type' => 'boolean', - 'weight' => -5, - ] + $base_plugin_definition, + 'label' => 'Mobile', + 'type' => 'boolean', + 'weight' => -5, + ] + $base_plugin_definition, 'platform_os' => [ - 'label' => 'Operating System', - 'type' => 'select', - 'options_callback' => [get_class($this), 'getOSOptions'], - ] + $base_plugin_definition, + 'label' => 'Operating System', + 'type' => 'select', + 'options_callback' => [get_class($this), 'getOSOptions'], + ] + $base_plugin_definition, 'cookie' => [ - 'label' => 'Cookie', - 'type' => 'key_value', - 'unique' => true, - ] + $base_plugin_definition, + 'label' => 'Cookie', + 'type' => 'key_value', + 'unique' => TRUE, + ] + $base_plugin_definition, 'cookie_enabled' => [ - 'label' => 'Cookie Enabled', - 'type' => 'boolean', - ] + $base_plugin_definition, + 'label' => 'Cookie Enabled', + 'type' => 'boolean', + ] + $base_plugin_definition, 'localstorage' => [ - 'label' => 'localStorage', - 'type' => 'key_value', - 'unique' => true, - ] + $base_plugin_definition, + 'label' => 'localStorage', + 'type' => 'key_value', + 'unique' => TRUE, + ] + $base_plugin_definition, 'width' => [ - 'label' => 'Width', - 'type' => 'number', - 'format_options' => [ - 'suffix' => 'px' - ] - ] + $base_plugin_definition, + 'label' => 'Width', + 'type' => 'number', + 'format_options' => [ + 'suffix' => 'px', + ], + ] + $base_plugin_definition, 'height' => [ - 'label' => 'Height', - 'type' => 'number', - 'format_options' => [ - 'suffix' => 'px' - ] - ] + $base_plugin_definition, + 'label' => 'Height', + 'type' => 'number', + 'format_options' => [ + 'suffix' => 'px', + ], + ] + $base_plugin_definition, ]; return $this->derivatives; } diff --git a/modules/smart_content_browser/src/Plugin/smart_content/Condition/BrowserCondition.php b/modules/smart_content_browser/src/Plugin/smart_content/Condition/BrowserCondition.php index 248dad2..5a617bd 100644 --- a/modules/smart_content_browser/src/Plugin/smart_content/Condition/BrowserCondition.php +++ b/modules/smart_content_browser/src/Plugin/smart_content/Condition/BrowserCondition.php @@ -25,4 +25,4 @@ class BrowserCondition extends ConditionTypeConfigurableBase { return $libraries; } -} \ No newline at end of file +} diff --git a/phpcs.xml b/phpcs.xml index 2423ab1..2909b97 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,13 +1,13 @@ - Drupal 8 coding standards + Drupal 8 coding standards - . - + . + - - README\.md - NOTES\.md + + README\.md + NOTES\.md - + diff --git a/smart_content.install b/smart_content.install index 6f89b39..574a877 100644 --- a/smart_content.install +++ b/smart_content.install @@ -1,17 +1,23 @@ execute(); - foreach($ids as $id) { + foreach ($ids as $id) { /** @var \Drupal\Core\Config\ImmutableConfig $config */ $config = \Drupal::service('config.factory')->getEditable('smart_content.smart_variation_set.' . $id); $data = $config->getRawData(); array_walk_recursive($data, - function(&$v, &$k) { - if ($v == 'variation_standard') $v = 'variation_block'; + function (&$v, &$k) { + if ($v == 'variation_standard') { + $v = 'variation_block'; + } } ); $config->setData($data)->save(); diff --git a/smart_content.libraries.yml b/smart_content.libraries.yml index fcd49aa..de9b6bb 100644 --- a/smart_content.libraries.yml +++ b/smart_content.libraries.yml @@ -14,7 +14,7 @@ condition.common: js: js/condition.common.js: { } dependencies: - - smart_content/decision + - smart_content/decision condition_type.standard: version: 1.x js: diff --git a/src/Annotation/SmartConditionType.php b/src/Annotation/SmartConditionType.php index 164001f..7fc4f08 100644 --- a/src/Annotation/SmartConditionType.php +++ b/src/Annotation/SmartConditionType.php @@ -29,4 +29,5 @@ class SmartConditionType extends Plugin { * @ingroup plugin_translatable */ public $label; + } diff --git a/src/Annotation/SmartReaction.php b/src/Annotation/SmartReaction.php index 586fc30..ae7fbf2 100644 --- a/src/Annotation/SmartReaction.php +++ b/src/Annotation/SmartReaction.php @@ -33,7 +33,8 @@ class SmartReaction extends Plugin { /** * The plugin ID. * - * @var boolean + * @var bool */ public $has_configuration_form; + } diff --git a/src/Condition/ConditionBase.php b/src/Condition/ConditionBase.php index bd01941..ea21f0f 100644 --- a/src/Condition/ConditionBase.php +++ b/src/Condition/ConditionBase.php @@ -4,9 +4,6 @@ namespace Drupal\smart_content\Condition; use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\PluginBase; -use Drupal\smart_content\Condition\ConditionInterface; -use Drupal\smart_content\ConditionSource\ConditionGroupInterface; -use Drupal\smart_content\ConditionType\ConditionTypeInterface; /** * Base class for Smart condition plugins. @@ -29,6 +26,9 @@ abstract class ConditionBase extends PluginBase implements ConditionInterface, C return isset($this->configuration['id']) ? $this->configuration['id'] : NULL; } + /** + * + */ public function getTypeId() { return 'plugin:' . $this->getPluginId(); } @@ -144,5 +144,5 @@ abstract class ConditionBase extends PluginBase implements ConditionInterface, C public function setConfiguration(array $configuration) { $this->configuration = $configuration + $this->defaultConfiguration(); } - + } diff --git a/src/Condition/ConditionConfigurableBase.php b/src/Condition/ConditionConfigurableBase.php index d3c102d..8dbc81d 100644 --- a/src/Condition/ConditionConfigurableBase.php +++ b/src/Condition/ConditionConfigurableBase.php @@ -3,7 +3,6 @@ namespace Drupal\smart_content\Condition; use Drupal\Core\Plugin\PluginFormInterface; -use Drupal\smart_content\Condition\ConditionBase; /** * Class ConditionConfigurableBase. @@ -16,4 +15,4 @@ use Drupal\smart_content\Condition\ConditionBase; */ abstract class ConditionConfigurableBase extends ConditionBase implements PluginFormInterface { -} \ No newline at end of file +} diff --git a/src/Condition/ConditionInterface.php b/src/Condition/ConditionInterface.php index 8177ee5..1baf896 100644 --- a/src/Condition/ConditionInterface.php +++ b/src/Condition/ConditionInterface.php @@ -9,8 +9,14 @@ use Drupal\Component\Plugin\PluginInspectionInterface; */ interface ConditionInterface extends PluginInspectionInterface { + /** + * + */ public function writeChangesToConfiguration(); + /** + * + */ public function getAttachedSettings(); } diff --git a/src/Condition/ConditionManager.php b/src/Condition/ConditionManager.php index f9b49b3..47e0663 100644 --- a/src/Condition/ConditionManager.php +++ b/src/Condition/ConditionManager.php @@ -12,6 +12,7 @@ use Drupal\Component\Plugin\FallbackPluginManagerInterface; * Provides the Smart condition plugin manager. */ class ConditionManager extends DefaultPluginManager implements FallbackPluginManagerInterface { + /** * Constructor for SmartConditionManager objects. * @@ -30,7 +31,9 @@ class ConditionManager extends DefaultPluginManager implements FallbackPluginMan $this->conditionGroupManager = $condition_group_manager; } - + /** + * + */ public function getFormOptions() { $options = []; $condition_group_definitions = $this->conditionGroupManager->getDefinitions(); @@ -39,21 +42,21 @@ class ConditionManager extends DefaultPluginManager implements FallbackPluginMan self::stableSort($condition_group_definitions, function ($first, $second) { $first['weight'] = isset($first['weight']) ? $first['weight'] : 0; $second['weight'] = isset($second['weight']) ? $second['weight'] : 0; - return $first['weight'] > $second['weight']; + return $first['weight'] > $second['weight']; }); self::stableSort($condition_definitions, function ($first, $second) { $first['weight'] = isset($first['weight']) ? $first['weight'] : 0; $second['weight'] = isset($second['weight']) ? $second['weight'] : 0; - return $first['weight'] > $second['weight']; + return $first['weight'] > $second['weight']; }); - foreach($condition_group_definitions as $condition_group_definition) { + foreach ($condition_group_definitions as $condition_group_definition) { $options[$condition_group_definition['label']->render()] = []; } foreach ($condition_definitions as $plugin_id => $definition) { - if($definition['group'] !== 'hidden') { + if ($definition['group'] !== 'hidden') { if (isset($condition_group_definitions[$definition['group']])) { $label = $condition_group_definitions[$definition['group']]['label']; $options[$label->render()][$plugin_id] = $definition['label']; @@ -71,8 +74,11 @@ class ConditionManager extends DefaultPluginManager implements FallbackPluginMan return 'broken'; } + /** + * + */ public static function stableSort(array &$array, $cmp_function) { - if(count($array) < 2) { + if (count($array) < 2) { return; } $halfway = count($array) / 2; @@ -81,30 +87,32 @@ class ConditionManager extends DefaultPluginManager implements FallbackPluginMan self::stableSort($array1, $cmp_function); self::stableSort($array2, $cmp_function); - if(call_user_func($cmp_function, end($array1), reset($array2)) < 1) { + if (call_user_func($cmp_function, end($array1), reset($array2)) < 1) { $array = $array1 + $array2; return; } - $array = array(); + $array = []; reset($array1); reset($array2); - while(current($array1) && current($array2)) { - if(call_user_func($cmp_function, current($array1), current($array2)) < 1) { + while (current($array1) && current($array2)) { + if (call_user_func($cmp_function, current($array1), current($array2)) < 1) { $array[key($array1)] = current($array1); next($array1); - } else { + } + else { $array[key($array2)] = current($array2); next($array2); } } - while(current($array1)) { + while (current($array1)) { $array[key($array1)] = current($array1); next($array1); } - while(current($array2)) { + while (current($array2)) { $array[key($array2)] = current($array2); next($array2); } return; } + } diff --git a/src/Condition/ConditionTypeConfigurableBase.php b/src/Condition/ConditionTypeConfigurableBase.php index b95b691..5cfb56e 100644 --- a/src/Condition/ConditionTypeConfigurableBase.php +++ b/src/Condition/ConditionTypeConfigurableBase.php @@ -8,6 +8,9 @@ use Drupal\Core\Plugin\PluginFormInterface; use Drupal\smart_content\ConditionType\ConditionTypeManager; use Symfony\Component\DependencyInjection\ContainerInterface; +/** + * + */ abstract class ConditionTypeConfigurableBase extends ConditionBase implements PluginFormInterface, ContainerFactoryPluginInterface { /** @@ -104,7 +107,11 @@ abstract class ConditionTypeConfigurableBase extends ConditionBase implements Pl return $this->conditionType; } + /** + * + */ public function getTypeId() { return 'type:' . $this->getConditionType()->getPluginId(); } + } diff --git a/src/ConditionGroup/ConditionGroupBase.php b/src/ConditionGroup/ConditionGroupBase.php index f23a4bc..b719521 100644 --- a/src/ConditionGroup/ConditionGroupBase.php +++ b/src/ConditionGroup/ConditionGroupBase.php @@ -3,7 +3,6 @@ namespace Drupal\smart_content\ConditionGroup; use Drupal\Component\Plugin\PluginBase; -use Drupal\smart_content\ConditionGroup\ConditionGroupInterface; /** * Base class for Smart condition source plugins. @@ -11,5 +10,4 @@ use Drupal\smart_content\ConditionGroup\ConditionGroupInterface; abstract class ConditionGroupBase extends PluginBase implements ConditionGroupInterface { // Add common methods and abstract methods for your plugin type here. - } diff --git a/src/ConditionGroup/ConditionGroupInterface.php b/src/ConditionGroup/ConditionGroupInterface.php index 55a896d..b66d3e7 100644 --- a/src/ConditionGroup/ConditionGroupInterface.php +++ b/src/ConditionGroup/ConditionGroupInterface.php @@ -11,5 +11,4 @@ interface ConditionGroupInterface extends PluginInspectionInterface { // Add get/set methods for your plugin type here. - } diff --git a/src/ConditionGroup/ConditionGroupManager.php b/src/ConditionGroup/ConditionGroupManager.php index 498d87f..02cb4e5 100644 --- a/src/ConditionGroup/ConditionGroupManager.php +++ b/src/ConditionGroup/ConditionGroupManager.php @@ -5,6 +5,7 @@ namespace Drupal\smart_content\ConditionGroup; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Traversable; /** * Provides the Smart condition source plugin manager. @@ -22,7 +23,7 @@ class ConditionGroupManager extends DefaultPluginManager { * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook with. */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { + public function __construct(Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { parent::__construct('Plugin/smart_content/ConditionGroup', $namespaces, $module_handler, 'Drupal\smart_content\ConditionGroup\ConditionGroupInterface', 'Drupal\smart_content\Annotation\SmartConditionGroup'); $this->alterInfo('smart_content_smart_condition_source_info'); diff --git a/src/ConditionType/ConditionTypeBase.php b/src/ConditionType/ConditionTypeBase.php index dcde5f4..e2c967b 100644 --- a/src/ConditionType/ConditionTypeBase.php +++ b/src/ConditionType/ConditionTypeBase.php @@ -6,7 +6,6 @@ use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; -use Drupal\smart_content\ConditionType\ConditionTypeInterface; /** * Base class for Smart condition type plugins. @@ -23,6 +22,7 @@ abstract class ConditionTypeBase extends PluginBase implements ConditionTypeInte public function getLibraries() { return []; } + /** * @inheritdoc */ @@ -34,7 +34,6 @@ abstract class ConditionTypeBase extends PluginBase implements ConditionTypeInte * * Because ConditionTypes act as widgets, we are storing the form_state * values automatically to configuration. - * */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { $this->setConfiguration($form_state->getValues()); @@ -68,8 +67,11 @@ abstract class ConditionTypeBase extends PluginBase implements ConditionTypeInte // TODO: Implement calculateDependencies() method. } + /** + * + */ public function getFieldAttachedSettings() { return []; } -} +} diff --git a/src/ConditionType/ConditionTypeInterface.php b/src/ConditionType/ConditionTypeInterface.php index 9732f55..ac9bbce 100644 --- a/src/ConditionType/ConditionTypeInterface.php +++ b/src/ConditionType/ConditionTypeInterface.php @@ -9,7 +9,9 @@ use Drupal\Component\Plugin\PluginInspectionInterface; */ interface ConditionTypeInterface extends PluginInspectionInterface { - // Returns data required for processing conditions. + /** + * Returns data required for processing conditions. + */ public function getAttachedSettings(); } diff --git a/src/ConditionType/ConditionTypeManager.php b/src/ConditionType/ConditionTypeManager.php index f6382a1..6748dbb 100644 --- a/src/ConditionType/ConditionTypeManager.php +++ b/src/ConditionType/ConditionTypeManager.php @@ -32,6 +32,9 @@ class ConditionTypeManager extends DefaultPluginManager { $this->setCacheBackend($cache_backend, 'smart_content_smart_condition_type_plugins'); } + /** + * + */ public function isPluginForm($condition_type) { if (!isset($this->plugin_form_exists[$condition_type])) { $this->plugin_form_exists[$condition_type] = $this->createInstance($condition_type) instanceof PluginFormInterface; diff --git a/src/Controller/DecisionController.php b/src/Controller/DecisionController.php index fca98cf..ad3416a 100644 --- a/src/Controller/DecisionController.php +++ b/src/Controller/DecisionController.php @@ -65,7 +65,7 @@ class DecisionController extends ControllerBase { public function reaction(SmartVariationSetInterface $entity, $variation_id) { $response = new AjaxResponse(); $context = \Drupal::request()->query->all(); - if($entity->validateReactionRequest($variation_id, $context)) { + if ($entity->validateReactionRequest($variation_id, $context)) { $response = $entity->getVariationResponse($variation_id, $context); } // Dispatch an event with the winning variation so other modules can attach diff --git a/src/DecisionAgent/DecisionAgentBase.php b/src/DecisionAgent/DecisionAgentBase.php index 7a12da8..22f7113 100644 --- a/src/DecisionAgent/DecisionAgentBase.php +++ b/src/DecisionAgent/DecisionAgentBase.php @@ -4,23 +4,24 @@ namespace Drupal\smart_content\DecisionAgent; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Template\Attribute; -use Drupal\smart_content\Entity\SmartVariationSetInterface; /** * Base class for Smart decision agent plugins. */ abstract class DecisionAgentBase extends PluginBase implements DecisionAgentInterface { - + /** + * + */ public function renderPlaceholder($context = []) { - //@todo: determine if VariationSetTypes should be able to append attributes and how would that work for modules to extend it during processing. + // @todo: determine if VariationSetTypes should be able to append attributes and how would that work for modules to extend it during processing. $attributes = new Attribute( [$this->getPluginDefinition()['placeholder_attribute'] => $this->entity->getPlaceholderDecisionId()] ); - foreach($context as $key => $value) { + foreach ($context as $key => $value) { $attributes->setAttribute('data-context-' . $key, $value); } - if($default_variation_id = $this->entity->getDefaultVariation()) { + if ($default_variation_id = $this->entity->getDefaultVariation()) { $attributes->setAttribute('data-default-id', $default_variation_id); } $output['placeholder'] = [ @@ -29,7 +30,11 @@ abstract class DecisionAgentBase extends PluginBase implements DecisionAgentInte return $output; } + /** + * + */ public function getResponseTarget() { return '[' . $this->getPluginDefinition()['placeholder_attribute'] . '="' . $this->entity->getPlaceholderDecisionId() . '"]'; } + } diff --git a/src/DecisionAgent/DecisionAgentManager.php b/src/DecisionAgent/DecisionAgentManager.php index 6d244a3..f4c11c5 100644 --- a/src/DecisionAgent/DecisionAgentManager.php +++ b/src/DecisionAgent/DecisionAgentManager.php @@ -12,7 +12,6 @@ use Drupal\smart_content\Entity\SmartVariationSetInterface; */ class DecisionAgentManager extends DefaultPluginManager { - /** * Constructor for DecisionAgentManager objects. * @@ -30,6 +29,7 @@ class DecisionAgentManager extends DefaultPluginManager { $this->alterInfo('smart_content_smart_decision_agent_info'); $this->setCacheBackend($cache_backend, 'smart_content_smart_decision_agent_plugins'); } + /** * {@inheritdoc} */ @@ -41,4 +41,5 @@ class DecisionAgentManager extends DefaultPluginManager { $plugin->entity = $entity; return $plugin; } + } diff --git a/src/Entity/SmartVariationSet.php b/src/Entity/SmartVariationSet.php index b8daa1f..6122386 100644 --- a/src/Entity/SmartVariationSet.php +++ b/src/Entity/SmartVariationSet.php @@ -68,7 +68,7 @@ class SmartVariationSet extends ConfigEntityBase implements SmartVariationSetInt /** * The wrapper object for this entity. * - * @var VariationSetTypeInterface + * @var \Drupal\smart_content\VariationSetType\VariationSetTypeInterface */ protected $variationSetTypeInstance; @@ -86,7 +86,7 @@ class SmartVariationSet extends ConfigEntityBase implements SmartVariationSetInt if (!isset($this->variationSetTypeInstance)) { $this->variationSetTypeInstance = NULL; $instance = $this->getVariationSetTypeFromSettings(); - if($instance instanceof VariationSetTypeInterface) { + if ($instance instanceof VariationSetTypeInterface) { $this->setVariationSetType($instance); } } @@ -107,7 +107,7 @@ class SmartVariationSet extends ConfigEntityBase implements SmartVariationSetInt if ($variation->id() === NULL) { $variation->setId($this->generateUniquePluginId($variation, array_keys($this->getVariations()))); } - //@todo: find better way to do this. + // @todo: find better way to do this. $this->variations[$variation->id()] = $variation; } @@ -237,7 +237,7 @@ class SmartVariationSet extends ConfigEntityBase implements SmartVariationSetInt * Get decision agent. * * @return \Drupal\smart_content\DecisionAgent\DecisionAgentInterface - * //@todo: refactor with proper configuration handling. + * //@todo: refactor with proper configuration handling. */ public function getDecisionAgent() { if (!isset($this->decisionAgentInstance)) { @@ -302,7 +302,7 @@ class SmartVariationSet extends ConfigEntityBase implements SmartVariationSetInt * * @return string */ - function getPlaceholderDecisionId() { + public function getPlaceholderDecisionId() { return $this->getEntityTypeId() . '.' . $this->id(); } @@ -331,7 +331,7 @@ class SmartVariationSet extends ConfigEntityBase implements SmartVariationSetInt * @return mixed */ public function validateReactionRequest($variation_id, $context = []) { - if($this->getVariation($variation_id)) { + if ($this->getVariation($variation_id)) { return $this->getVariationSetType()->validateReactionRequest($variation_id, $context = []); } } @@ -342,9 +342,9 @@ class SmartVariationSet extends ConfigEntityBase implements SmartVariationSetInt * @return mixed */ public function getDefaultVariation() { - if(!empty($this->default_variation)) { + if (!empty($this->default_variation)) { // Confirm variation exists. - if($this->getVariation($this->default_variation)) { + if ($this->getVariation($this->default_variation)) { return $this->default_variation; } } @@ -358,5 +358,5 @@ class SmartVariationSet extends ConfigEntityBase implements SmartVariationSetInt public function setDefaultVariation($variation_id) { $this->default_variation = $variation_id; } - + } diff --git a/src/Form/SmartVariationSetForm.php b/src/Form/SmartVariationSetForm.php index 85f4f72..48e4f52 100644 --- a/src/Form/SmartVariationSetForm.php +++ b/src/Form/SmartVariationSetForm.php @@ -157,14 +157,18 @@ class SmartVariationSetForm extends EntityForm { } } - + /** + * + */ public static function saveEntityState($form_state, $parents, $entity) { NestedArray::setValue($form_state->getStorage(), array_merge(['variation_sets'], $parents, ['entities']), $entity); } + /** + * + */ public static function getEntityState($form_state, $parents) { return NestedArray::getValue($form_state->getStorage(), array_merge(['variation_sets'], $parents, ['entities'])); } } - diff --git a/src/Plugin/smart_content/Condition/Broken.php b/src/Plugin/smart_content/Condition/Broken.php index 0f468dc..3686dd7 100644 --- a/src/Plugin/smart_content/Condition/Broken.php +++ b/src/Plugin/smart_content/Condition/Broken.php @@ -1,9 +1,8 @@ [ - 'negate' => false, - ] + 'negate' => FALSE, + ], ]; } - + } diff --git a/src/Plugin/smart_content/Condition/Group.php b/src/Plugin/smart_content/Condition/Group.php index 63b084a..380548f 100644 --- a/src/Plugin/smart_content/Condition/Group.php +++ b/src/Plugin/smart_content/Condition/Group.php @@ -9,7 +9,6 @@ use Drupal\Core\Plugin\PluginFormInterface; use Drupal\smart_content\Condition\ConditionBase; use Drupal\smart_content\Condition\ConditionConfigurableBase; use Drupal\smart_content\Condition\ConditionInterface; -use Drupal\smart_content\ConditionType\ConditionTypeBase; use Drupal\smart_content\Entity\SmartVariationSet; use Drupal\smart_content\Form\SmartVariationSetForm; @@ -26,7 +25,7 @@ use Drupal\smart_content\Form\SmartVariationSetForm; */ class Group extends ConditionConfigurableBase { - //@todo: determine best way to unset extra settings + // @todo: determine best way to unset extra settings /** * @inheritdoc @@ -85,7 +84,6 @@ class Group extends ConditionConfigurableBase { ], ]; - foreach ($this->getConditions() as $condition_id => $condition) { if ($condition instanceof PluginFormInterface) { SmartVariationSetForm::pluginForm($condition, $form, $form_state, [ @@ -179,15 +177,24 @@ class Group extends ConditionConfigurableBase { return $element; } - function defaultFieldConfiguration() { + /** + * + */ + public function defaultFieldConfiguration() { return []; } + /** + * + */ public function evaluate($values, $context) { return (bool) $context; } - function getLibraries() { + /** + * + */ + public function getLibraries() { $libraries = ['smart_content/condition.common']; foreach ($this->getConditions() as $condition) { $libraries = array_merge($libraries, $condition->getLibraries()); @@ -257,6 +264,9 @@ class Group extends ConditionConfigurableBase { unset($this->conditions[$id]); } + /** + * + */ protected function getConditionsFromSettings() { $plugins = []; if (!empty($this->getConfiguration()['conditions_settings'])) { @@ -275,7 +285,9 @@ class Group extends ConditionConfigurableBase { return $plugins; } - // @todo: determine if there is a better way to do this. copy better way to block form. + /** + * @todo: determine if there is a better way to do this. copy better way to block form. + */ public function attachTableConditionWeight($values) { foreach ($this->getConditions() as $condition) { if (isset($values[$condition->id()]['weight'])) { @@ -285,6 +297,9 @@ class Group extends ConditionConfigurableBase { $this->sortConditions(); } + /** + * + */ public function addElementConditionValidate(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); $array_parents = array_slice($button['#array_parents'], 0, -1); @@ -295,6 +310,9 @@ class Group extends ConditionConfigurableBase { } } + /** + * + */ public function addElementCondition(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); // Save condition weight. @@ -305,18 +323,24 @@ class Group extends ConditionConfigurableBase { $type = NestedArray::getValue($form_state->getUserInput(), array_slice($button['#parents'], 0, -1))['condition_type']; - //@todo: Fix nested + // @todo: Fix nested $this->addCondition(\Drupal::service('plugin.manager.smart_content.condition') ->createInstance($type)); $form_state->setRebuild(); } + /** + * + */ public function addElementConditionAjax(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); // Go one level up in the form, to the widgets container. return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2)); } + /** + * + */ public function removeElementCondition(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); @@ -329,18 +353,24 @@ class Group extends ConditionConfigurableBase { $this->attachTableConditionWeight($condition_values['condition_items']); } - //@todo: add nested remove functionality. + // @todo: add nested remove functionality. $this->removeCondition($name); $form_state->setRebuild(); } + /** + * + */ public function removeElementConditionAjax(array &$form, FormStateInterface $form_state) { $button = $form_state->getTriggeringElement(); // Go one level up in the form, to the widgets container. return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -3)); } + /** + * + */ public function sortConditions() { if ($this->getConditions()) { uasort($this->conditions, function ($first, $second) { diff --git a/src/Plugin/smart_content/ConditionGroup/Common.php b/src/Plugin/smart_content/ConditionGroup/Common.php index 5939e29..5a00597 100644 --- a/src/Plugin/smart_content/ConditionGroup/Common.php +++ b/src/Plugin/smart_content/ConditionGroup/Common.php @@ -2,7 +2,6 @@ namespace Drupal\smart_content\Plugin\smart_content\ConditionGroup; -use Drupal\smart_content\Annotation\SmartConditionGroup; use Drupal\smart_content\ConditionGroup\ConditionGroupBase; /** diff --git a/src/Plugin/smart_content/ConditionType/Boolean.php b/src/Plugin/smart_content/ConditionType/Boolean.php index 1e098c2..4f01b64 100644 --- a/src/Plugin/smart_content/ConditionType/Boolean.php +++ b/src/Plugin/smart_content/ConditionType/Boolean.php @@ -40,7 +40,7 @@ class Boolean extends ConditionTypeBase { /** * @inheritdoc */ - function defaultFieldConfiguration() { + public function defaultFieldConfiguration() { return []; } @@ -54,12 +54,15 @@ class Boolean extends ConditionTypeBase { /** * @inheritdoc */ - function getLibraries() { + public function getLibraries() { return ['smart_content/condition_type.standard']; } - + /** + * + */ public function getAttachedSettings() { return $this->getConfiguration() + $this->defaultFieldConfiguration(); } -} \ No newline at end of file + +} diff --git a/src/Plugin/smart_content/ConditionType/KeyValue.php b/src/Plugin/smart_content/ConditionType/KeyValue.php index cecd082..c88d813 100644 --- a/src/Plugin/smart_content/ConditionType/KeyValue.php +++ b/src/Plugin/smart_content/ConditionType/KeyValue.php @@ -16,7 +16,8 @@ use Drupal\smart_content\ConditionType\ConditionTypeBase; */ class KeyValue extends ConditionTypeBase { - //@todo: add format_options + // @todo: add format_options + /** * @inheritdoc */ @@ -33,7 +34,7 @@ class KeyValue extends ConditionTypeBase { $form['label'] = [ '#type' => 'container', - //@todo: get condition group name from group + // @todo: get condition group name from group '#markup' => $condition_definition['label'] . '(' . $condition_definition['group'] . ')', '#attributes' => ['class' => ['condition-label']], ]; @@ -56,7 +57,7 @@ class KeyValue extends ConditionTypeBase { '#required' => TRUE, '#default_value' => isset($this->configuration['value']) ? $this->configuration['value'] : $this->defaultFieldConfiguration()['value'], '#attributes' => ['class' => ['condition-value']], - //@todo: make configurable + // @todo: make configurable '#size' => 20, ]; @@ -64,6 +65,9 @@ class KeyValue extends ConditionTypeBase { return $form; } + /** + * + */ public function buildWidget(array &$element, FormStateInterface $form_state, array &$complete_form) { if (!empty($element['#parents'])) { $parents = $element['#parents']; @@ -86,8 +90,10 @@ class KeyValue extends ConditionTypeBase { return $element; } - //@todo: replace default Field configuration with configurable - function defaultFieldConfiguration() { + /** + * @todo: replace default Field configuration with configurable + */ + public function defaultFieldConfiguration() { return [ 'key' => '', 'op' => 'equals', @@ -95,7 +101,10 @@ class KeyValue extends ConditionTypeBase { ]; } - function getOperators() { + /** + * + */ + public function getOperators() { return [ 'equals' => 'Equals', 'starts_with' => 'Starts with', @@ -104,11 +113,16 @@ class KeyValue extends ConditionTypeBase { ]; } - - function getLibraries() { + /** + * + */ + public function getLibraries() { return ['smart_content/condition_type.standard']; } + /** + * + */ public function getAttachedSettings() { $configuration = $this->getConfiguration(); return [ @@ -118,11 +132,14 @@ class KeyValue extends ConditionTypeBase { ]; } - + /** + * + */ public function getFieldAttachedSettings() { $configuration = $this->getConfiguration(); return [ 'key' => $configuration['key'], ]; } -} \ No newline at end of file + +} diff --git a/src/Plugin/smart_content/ConditionType/Number.php b/src/Plugin/smart_content/ConditionType/Number.php index 534d669..51d6fad 100644 --- a/src/Plugin/smart_content/ConditionType/Number.php +++ b/src/Plugin/smart_content/ConditionType/Number.php @@ -16,7 +16,8 @@ use Drupal\smart_content\ConditionType\ConditionTypeBase; */ class Number extends ConditionTypeBase { - //@todo: add format_options + // @todo: add format_options + /** * {@inheritdoc} */ @@ -26,7 +27,7 @@ class Number extends ConditionTypeBase { $form['label'] = [ '#type' => 'container', - //@todo: get condition group name from group + // @todo: get condition group name from group '#markup' => $condition_definition['label'] . '(' . $condition_definition['group'] . ')', '#attributes' => ['class' => ['condition-label']], ]; @@ -40,10 +41,10 @@ class Number extends ConditionTypeBase { '#required' => TRUE, '#default_value' => isset($this->configuration['value']) ? $this->configuration['value'] : $this->defaultFieldConfiguration()['value'], ]; - if(isset($condition_definition['format_options']['prefix'])) { + if (isset($condition_definition['format_options']['prefix'])) { $form['value']['#prefix'] = $condition_definition['format_options']['prefix']; } - if(isset($condition_definition['format_options']['suffix'])) { + if (isset($condition_definition['format_options']['suffix'])) { $form['value']['#suffix'] = $condition_definition['format_options']['suffix']; } return $form; @@ -98,12 +99,18 @@ class Number extends ConditionTypeBase { return FALSE; } - - function getLibraries() { + /** + * + */ + public function getLibraries() { return ['smart_content/condition_type.standard']; } + /** + * + */ public function getAttachedSettings() { return $this->getConfiguration() + $this->defaultFieldConfiguration(); } + } diff --git a/src/Plugin/smart_content/ConditionType/Select.php b/src/Plugin/smart_content/ConditionType/Select.php index fd253c3..c62d76b 100644 --- a/src/Plugin/smart_content/ConditionType/Select.php +++ b/src/Plugin/smart_content/ConditionType/Select.php @@ -22,7 +22,7 @@ class Select extends ConditionTypeBase { public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $condition_definition = $this->conditionInstance->getPluginDefinition(); $form = ConditionBase::attachNegateElement($form, $this->configuration); - + $options = []; // If 'options' are defined in definition, populate options. if (isset($condition_definition['options'])) { @@ -31,13 +31,13 @@ class Select extends ConditionTypeBase { // If 'options_callback' is defined in definition, validate and populate options. elseif (isset($condition_definition['options_callback'])) { // Confirm 'options_callback' is callable function/method. - if(is_callable($condition_definition['options_callback'], FALSE, $callable_name)) { + if (is_callable($condition_definition['options_callback'], FALSE, $callable_name)) { $options = call_user_func($condition_definition['options_callback']); } } $form['label'] = [ '#type' => 'container', - //@todo: get condition group name from group + // @todo: get condition group name from group '#markup' => $condition_definition['label'] . '(' . $condition_definition['group'] . ')', '#attributes' => ['class' => ['condition-label']], ]; @@ -50,6 +50,9 @@ class Select extends ConditionTypeBase { return $form; } + /** + * + */ public function evaluate($values, $context) { if (isset($values['value'], $context)) { } @@ -65,11 +68,18 @@ class Select extends ConditionTypeBase { ]; } - function getLibraries() { + /** + * + */ + public function getLibraries() { return ['smart_content/condition_type.standard']; } + /** + * + */ public function getAttachedSettings() { return $this->getConfiguration() + $this->defaultFieldConfiguration(); } + } diff --git a/src/Plugin/smart_content/ConditionType/Textfield.php b/src/Plugin/smart_content/ConditionType/Textfield.php index ad94573..23905e0 100644 --- a/src/Plugin/smart_content/ConditionType/Textfield.php +++ b/src/Plugin/smart_content/ConditionType/Textfield.php @@ -16,7 +16,8 @@ use Drupal\smart_content\ConditionType\ConditionTypeBase; */ class Textfield extends ConditionTypeBase { - //@todo: add format_options + // @todo: add format_options + /** * @inheritdoc */ @@ -33,7 +34,7 @@ class Textfield extends ConditionTypeBase { $form['label'] = [ '#type' => 'container', - //@todo: get condition group name from group + // @todo: get condition group name from group '#markup' => $condition_definition['label'] . '(' . $condition_definition['group'] . ')', '#attributes' => ['class' => ['condition-label']], ]; @@ -48,7 +49,7 @@ class Textfield extends ConditionTypeBase { '#required' => TRUE, '#default_value' => isset($this->configuration['value']) ? $this->configuration['value'] : $this->defaultFieldConfiguration()['value'], '#attributes' => ['class' => ['condition-value']], - //@todo: make configurable + // @todo: make configurable '#size' => 20, ]; @@ -56,6 +57,9 @@ class Textfield extends ConditionTypeBase { return $form; } + /** + * + */ public function buildWidget(array &$element, FormStateInterface $form_state, array &$complete_form) { if (!empty($element['#parents'])) { $parents = $element['#parents']; @@ -77,15 +81,20 @@ class Textfield extends ConditionTypeBase { return $element; } - //@todo: replace default Field configuration with configurable - function defaultFieldConfiguration() { + /** + * @todo: replace default Field configuration with configurable + */ + public function defaultFieldConfiguration() { return [ 'op' => 'equals', 'value' => '', ]; } - function getOperators() { + /** + * + */ + public function getOperators() { return [ 'equals' => 'Equals', 'starts_with' => 'Starts with', @@ -93,28 +102,41 @@ class Textfield extends ConditionTypeBase { ]; } + /** + * + */ public function evaluate($values, $context) { if (isset($values['value'], $values['op'], $context)) { switch ($values['op']) { case 'equals': return $values['value'] == $context; - break; + + break; case 'starts_with': return strpos($context, $values['value']) === 0; - break; + + break; case 'empty': return empty($context); - break; + + break; } } return FALSE; } - function getLibraries() { + /** + * + */ + public function getLibraries() { return ['smart_content/condition_type.standard']; } + /** + * + */ public function getAttachedSettings() { return $this->getConfiguration() + $this->defaultFieldConfiguration(); } -} \ No newline at end of file + +} diff --git a/src/Plugin/smart_content/DecisionAgent/Client.php b/src/Plugin/smart_content/DecisionAgent/Client.php index 6ae1ce3..6d01089 100644 --- a/src/Plugin/smart_content/DecisionAgent/Client.php +++ b/src/Plugin/smart_content/DecisionAgent/Client.php @@ -2,7 +2,6 @@ namespace Drupal\smart_content\Plugin\smart_content\DecisionAgent; -use Drupal\smart_content\Annotation\SmartDecisionAgent; use Drupal\smart_content\DecisionAgent\DecisionAgentBase; /** @@ -28,11 +27,18 @@ class Client extends DecisionAgentBase { // TODO: Implement getAttached() method. } + /** + * + */ public function getAttachedSettings() { } - function isProcessedClientSide() { + /** + * + */ + public function isProcessedClientSide() { return TRUE; } -} \ No newline at end of file + +} diff --git a/src/Plugin/smart_content/DecisionAgent/Server.php b/src/Plugin/smart_content/DecisionAgent/Server.php index cb74df5..fc0a524 100644 --- a/src/Plugin/smart_content/DecisionAgent/Server.php +++ b/src/Plugin/smart_content/DecisionAgent/Server.php @@ -2,7 +2,6 @@ namespace Drupal\smart_content\Plugin\smart_content\DecisionAgent; -use Drupal\smart_content\Annotation\SmartDecisionAgent; use Drupal\smart_content\DecisionAgent\DecisionAgentBase; /** @@ -27,11 +26,18 @@ class Server extends DecisionAgentBase { return ['smart_content/decision.server']; } + /** + * + */ public function getAttachedSettings() { } + /** + * + */ public function isProcessedClientSide() { return FALSE; } -} \ No newline at end of file + +} diff --git a/src/Reaction/ReactionBase.php b/src/Reaction/ReactionBase.php index 51b484e..b79899a 100644 --- a/src/Reaction/ReactionBase.php +++ b/src/Reaction/ReactionBase.php @@ -13,6 +13,7 @@ use Drupal\Core\DependencyInjection\DependencySerializationTrait; abstract class ReactionBase extends PluginBase implements ReactionInterface, ConfigurablePluginInterface { use DependencySerializationTrait; + /** * Sets ID of reaction. * @@ -84,6 +85,7 @@ abstract class ReactionBase extends PluginBase implements ReactionInterface, Con /** * {@inheritdoc} */ - function buildResponse(AjaxResponse $response) { + public function buildResponse(AjaxResponse $response) { } + } diff --git a/src/Reaction/ReactionConfigurableBase.php b/src/Reaction/ReactionConfigurableBase.php index 550a9f5..094ca01 100644 --- a/src/Reaction/ReactionConfigurableBase.php +++ b/src/Reaction/ReactionConfigurableBase.php @@ -2,10 +2,12 @@ namespace Drupal\smart_content\Reaction; - use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; +/** + * + */ abstract class ReactionConfigurableBase extends ReactionBase implements PluginFormInterface { /** @@ -22,7 +24,11 @@ abstract class ReactionConfigurableBase extends ReactionBase implements PluginFo $this->setConfiguration($form_state->getValues()); } + /** + * + */ public function writeChangesToConfiguration() { } -} \ No newline at end of file + +} diff --git a/src/Reaction/ReactionInterface.php b/src/Reaction/ReactionInterface.php index 9c0cbc5..55bcb60 100644 --- a/src/Reaction/ReactionInterface.php +++ b/src/Reaction/ReactionInterface.php @@ -11,5 +11,4 @@ interface ReactionInterface extends PluginInspectionInterface { // Add get/set methods for your plugin type here. - } diff --git a/src/Reaction/ReactionManager.php b/src/Reaction/ReactionManager.php index d81011d..3fa9e1e 100644 --- a/src/Reaction/ReactionManager.php +++ b/src/Reaction/ReactionManager.php @@ -12,7 +12,6 @@ use Drupal\smart_content\Entity\SmartVariationSetInterface; */ class ReactionManager extends DefaultPluginManager { - /** * Constructor for ReactionManager objects. * @@ -42,4 +41,5 @@ class ReactionManager extends DefaultPluginManager { $plugin->entity = $entity; return $plugin; } + } diff --git a/src/Variation/VariationBase.php b/src/Variation/VariationBase.php index ead2a92..5ee612d 100644 --- a/src/Variation/VariationBase.php +++ b/src/Variation/VariationBase.php @@ -16,7 +16,6 @@ use Drupal\smart_content\Reaction\ReactionManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; - /** * Base class for Smart variation plugins. */ @@ -34,7 +33,6 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C protected $reactions; - /** * Creates an instance of the plugin. * @@ -60,16 +58,25 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C ); } + /** + * + */ public function __construct(array $configuration, $plugin_id, $plugin_definition, ConditionManager $condition_manager, ReactionManager $reaction_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->conditionManager = $condition_manager; $this->reactionManager = $reaction_manager; } + /** + * + */ public function id() { return isset($this->configuration['id']) ? $this->configuration['id'] : NULL; } + /** + * + */ public function setId($id) { $configuration = $this->getConfiguration(); $configuration['id'] = $id; @@ -94,7 +101,6 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C // TODO: Implement calculateDependencies() method. } - /** * {@inheritdoc} */ @@ -109,12 +115,18 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C $this->configuration = $configuration + $this->defaultConfiguration(); } + /** + * + */ public function setWeight($weight) { $configuration = $this->getConfiguration(); $configuration['weight'] = $weight; $this->setConfiguration($configuration); } + /** + * + */ public function getWeight() { return isset($this->configuration['weight']) ? $this->configuration['weight'] : 0; } @@ -164,7 +176,9 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C unset($this->conditions[$id]); } - + /** + * + */ protected function getConditionsFromSettings() { $plugins = []; if (!empty($this->getConfiguration()['conditions_settings'])) { @@ -181,7 +195,9 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C return $plugins; } - + /** + * + */ public function sortConditions() { if ($this->getConditions()) { uasort($this->conditions, function ($first, $second) { @@ -190,11 +206,14 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C } } + /** + * + */ public function addReaction(ReactionInterface $reaction) { if ($reaction->id() === NULL) { $reaction->setId(SmartVariationSet::generateUniquePluginId($reaction, array_keys($this->getReactions()))); } - //@todo: find better way to do this. + // @todo: find better way to do this. $this->reactions[$reaction->id()] = $reaction; } @@ -233,7 +252,9 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C unset($this->reactions[$id]); } - + /** + * + */ protected function getReactionsFromSettings() { $plugins = []; if (!empty($this->getConfiguration()['reactions_settings'])) { @@ -244,7 +265,9 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C return $plugins; } - + /** + * + */ public function sortReactions() { if ($this->getReactions()) { uasort($this->reactions, function ($first, $second) { @@ -253,6 +276,9 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C } } + /** + * + */ public function writeChangesToConfiguration() { $configuration = $this->getConfiguration(); $conditions_settings = []; @@ -270,7 +296,9 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C $this->setConfiguration($configuration); } - + /** + * + */ public function getLibraries() { $libraries = []; @@ -281,7 +309,9 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C return $libraries; } - + /** + * + */ public function getAttachedSettings() { $condition_settings = []; foreach ($this->getConditions() as $condition) { @@ -293,8 +323,10 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C ]; } - - function getResponse($context = []) { + /** + * + */ + public function getResponse($context = []) { $response = new AjaxResponse(); $content = []; foreach ($this->getReactions() as $reaction) { @@ -310,8 +342,9 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C return $response; } - - + /** + * + */ public function attachTableConditionWeight($values) { foreach ($this->getConditions() as $condition) { if (isset($values[$condition->id()]['weight'])) { @@ -321,8 +354,9 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C $this->sortConditions(); } - - + /** + * + */ public function attachTableReactionWeight($values) { foreach ($this->getReactions() as $reaction) { if (isset($values[$reaction->id()]['weight'])) { @@ -331,5 +365,5 @@ abstract class VariationBase extends PluginBase implements VariationInterface, C } $this->sortReactions(); } -} +} diff --git a/src/Variation/VariationInterface.php b/src/Variation/VariationInterface.php index 7c4e75b..80a4ced 100644 --- a/src/Variation/VariationInterface.php +++ b/src/Variation/VariationInterface.php @@ -9,8 +9,10 @@ use Drupal\Component\Plugin\PluginInspectionInterface; */ interface VariationInterface extends PluginInspectionInterface { + /** + * + */ public function writeChangesToConfiguration(); // Add get/set methods for your plugin type here. - } diff --git a/src/Variation/VariationManager.php b/src/Variation/VariationManager.php index 6652e96..d7236c9 100644 --- a/src/Variation/VariationManager.php +++ b/src/Variation/VariationManager.php @@ -12,7 +12,6 @@ use Drupal\smart_content\Entity\SmartVariationSetInterface; */ class VariationManager extends DefaultPluginManager { - /** * Constructor for SmartVariationManager objects. * diff --git a/src/VariationSetType/VariationSetTypeBase.php b/src/VariationSetType/VariationSetTypeBase.php index b7e27ee..53eb297 100644 --- a/src/VariationSetType/VariationSetTypeBase.php +++ b/src/VariationSetType/VariationSetTypeBase.php @@ -42,6 +42,9 @@ abstract class VariationSetTypeBase extends PluginBase implements VariationSetTy $this->configuration = $configuration + $this->defaultConfiguration(); } + /** + * + */ public function writeChangesToConfiguration() { $configuration = $this->getConfiguration(); $this->setConfiguration($configuration); @@ -54,6 +57,9 @@ abstract class VariationSetTypeBase extends PluginBase implements VariationSetTy return TRUE; } + /** + * + */ public function attachTableVariationWeight($values) { foreach ($this->entity->getVariations() as $variation) { if (isset($values[$variation->id()]['weight'])) { diff --git a/src/VariationSetType/VariationSetTypeManager.php b/src/VariationSetType/VariationSetTypeManager.php index 6968661..2f514d7 100644 --- a/src/VariationSetType/VariationSetTypeManager.php +++ b/src/VariationSetType/VariationSetTypeManager.php @@ -12,7 +12,6 @@ use Drupal\smart_content\Entity\SmartVariationSetInterface; */ class VariationSetTypeManager extends DefaultPluginManager { - /** * Constructor for SmartVariationManager objects. * @@ -31,7 +30,6 @@ class VariationSetTypeManager extends DefaultPluginManager { $this->setCacheBackend($cache_backend, 'smart_content_smart_variation_set_type_plugins'); } - /** * {@inheritdoc} */