You are here

protected function AddContentByBundle::extractParams in Add Content by Bundle Views Area Plugin 1.x

Parse provided text into key-value pairs, checking for tokens.

Parameters

array $params: The array to which parsed values will be added.

string $input: The configured input to parse.

1 call to AddContentByBundle::extractParams()
AddContentByBundle::render in src/Plugin/views/area/AddContentByBundle.php
Render the area.

File

src/Plugin/views/area/AddContentByBundle.php, line 287

Class

AddContentByBundle
Defines an area plugin to display a bundle-specific node/add link.

Namespace

Drupal\add_content_by_bundle\Plugin\views\area

Code

protected function extractParams(array &$params, $input) {
  $list = explode("\n", $input);
  $list = array_map('trim', $list);
  $list = array_filter($list, 'strlen');
  $display = $this->view
    ->getDisplay();

  // @todo possible to support additional tokens?
  $tokens = $display
    ->getArgumentsTokens();
  foreach ($list as $text) {

    // Check for an explicit key.
    $matches = [];
    if (preg_match('/(.*)\\|(.*)/', $text, $matches)) {

      // Trim key and value to avoid unwanted spaces issues.
      $key = trim($matches[1]);
      $value = trim($matches[2]);
    }
    elseif (strlen($text) <= 255) {
      $key = $value = $text;
    }

    // Check for tokens in the value.
    if ($tokens) {
      $value = $display
        ->viewsTokenReplace($value, $tokens);
    }
    $params[$key] = $value;
  }
}