You are here

abstract class AjaxCommandBase in Forena Reports 7.4

Same name and namespace in other branches
  1. 8 src/FrxPlugin/AjaxCommand/AjaxCommandBase.php \Drupal\forena\FrxPlugin\AjaxCommand\AjaxCommandBase

Hierarchy

Expanded class hierarchy of AjaxCommandBase

File

AjaxCommand/AjaxCommandBase.php, line 14

Namespace

Drupal\forena\FrxPlugin\AjaxCommand
View source
abstract class AjaxCommandBase implements AjaxCommandInterface {
  protected $replacer;

  /**
   * AjaxCommandBase constructor.
   * @param \FrxSyntaxEngine $replacer
   *   Token replacer
   */
  public function __construct($replacer) {
    $this->replacer = $replacer;
  }

  /**
   * @param $settings
   * @param $key
   * @return mixed
   *   The settings in the array
   */
  public function getSetting(&$settings, $key) {
    $value = NULL;
    if (isset($settings[$key])) {
      $value = $settings[$key];
      unset($settings[$key]);
    }
    $this->replacer
      ->replaceNested($value);
    return $value;
  }

  /**
   * @param array $settings
   * @param string $default_key
   *   The key to look for if the text
   *
   */
  public function getJSONText(&$settings, $default_key = '') {
    $data = [];
    if ($default_key && isset($settings[$default_key])) {
      $data = $settings[$default_key];
      unset($settings[$default_key]);
    }
    if (!empty($settings['text'])) {
      $data = $settings['text'];
      unset($settings['text']);
    }
    if (!is_array($data) || !is_object($data)) {
      $data = @json_decode($data);
      if (!$data) {
        $data = [];
      }
    }
    $this->replacer
      ->replaceNested($data);
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AjaxCommandBase::$replacer protected property
AjaxCommandBase::getJSONText public function
AjaxCommandBase::getSetting public function
AjaxCommandBase::__construct public function AjaxCommandBase constructor.
AjaxCommandInterface::commandFromSettings public function Settings are passed into this factory from either the skin or the report element. If there are complex structures when used in the arguments they will be passed in the 'text' setting. These should be decoded by any plugin intending to use… 15