unpackOptions example

// Create a new handler and unpack the options from the form onto it. We     // can use that for storage.     $handler = Views::handlerManager($handler_type)->getHandler($item$override);
    $handler->init($executable$executable->display_handler, $item);

    // Add the incoming options to existing options because items using     // the extra form may not have everything in the form here.     $options = $handler->submitFormCalculateOptions($handler->options, $form_state->getValue('options', []));

    // This unpacks only options that are in the definition, ensuring random     // extra stuff on the form is not sent through.     $handler->unpackOptions($handler->options, $options, NULL, FALSE);

    // Store the item back on the view     $executable->setHandler($display_id$type$id$handler->options);

    // Ensure any temporary options are removed.     if (isset($view->temporary_options[$type][$id])) {
      unset($view->temporary_options[$type][$id]);
    }

    // Write to cache     $view->cacheSet();
  }
/** * {@inheritdoc} */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view$display$options);

    // Check to see if this handler type is defaulted. Note that     // we have to do a lookup because the type is singular but the     // option is stored as the plural.
    $this->unpackOptions($this->options, $options);

    // This exist on most handlers, but not all. So they are still optional.     if (isset($options['table'])) {
      $this->table = $options['table'];
    }

    // Allow aliases on both fields and tables.     if (isset($this->definition['real table'])) {
      $this->table = $this->definition['real table'];
    }

    


  /** * {@inheritdoc} */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    $this->view = $view;
    $this->options = $this->options ?? [];
    $this->setOptionDefaults($this->options, $this->defineOptions());
    $this->displayHandler = $display;

    $this->unpackOptions($this->options, $options);
  }

  /** * Information about options for all kinds of purposes will be held here. * @code * 'option_name' => array( * - 'default' => default value, * - 'contains' => (optional) array of items this contains, with its own * defaults, etc. If contains is set, the default will be ignored and * assumed to be array(). * ), * @endcode * * @return array * Returns the options of this handler/plugin. */

  public function testUnpackOptions($storage$options$definition$expected$all = FALSE) {
    $this->testHelperPlugin->unpackOptions($storage$options$definition$all);
    $this->assertEquals($storage$expected);
  }

  /** * Tests the setOptionDefault method. * * @param array $storage * The storage array to unpack option into. * @param array $definition * The definition array, defining default options. * @param array $expected * The expected array after unpacking * * @dataProvider providerTestSetOptionDefault * @covers ::setOptionDefaults */
$skip_cache = \Drupal::config('views.settings')->get('skip_cache');

    if (!$skip_cache) {
      $cid = 'views:unpack_options:' . hash('sha256', serialize([$this->options, $options])) . ':' . \Drupal::languageManager()->getCurrentLanguage()->getId();
      if (empty(static::$unpackOptions[$cid])) {
        $cache = \Drupal::cache('data')->get($cid);
        if (!empty($cache->data)) {
          $this->options = $cache->data;
        }
        else {
          $this->unpackOptions($this->options, $options);
          \Drupal::cache('data')->set($cid$this->options, Cache::PERMANENT, $this->view->storage->getCacheTags());
        }
        static::$unpackOptions[$cid] = $this->options;
      }
      else {
        $this->options = static::$unpackOptions[$cid];
      }
    }
    else {
      $this->unpackOptions($this->options, $options);
    }

    
Home | Imprint | This part of the site doesn't use cookies.