You are here

class RowsOfMultiValueFields in Search API 8

Outputs multi-valued data as comma-separated values.

This is used in the Drush integration.

Hierarchy

  • class \Drupal\search_api\Contrib\RowsOfMultiValueFields extends \Consolidation\OutputFormatters\StructuredData\RowsOfFields implements \Consolidation\OutputFormatters\StructuredData\RenderCellInterface

Expanded class hierarchy of RowsOfMultiValueFields

1 file declares its use of RowsOfMultiValueFields
SearchApiCommands.php in src/Commands/SearchApiCommands.php

File

src/Contrib/RowsOfMultiValueFields.php, line 14

Namespace

Drupal\search_api\Contrib
View source
class RowsOfMultiValueFields extends RowsOfFields implements RenderCellInterface {

  /**
   * {@inheritdoc}
   */
  public function renderCell($key, $cellData, FormatterOptions $options, $rowData) {
    if (is_array($cellData)) {
      return static::arrayToString($cellData);
    }
    return $cellData;
  }

  /**
   * Converts an array of string data into a comma separated string.
   *
   * @param array $array
   *   A multidimensional array of string data.
   *
   * @return string
   *   A comma separated string.
   */
  protected static function arrayToString(array $array) {
    $elements = [];
    foreach ($array as $element) {
      $elements[] = is_array($element) ? '"' . static::arrayToString($element) . '"' : $element;
    }
    return implode(',', $elements);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RowsOfMultiValueFields::arrayToString protected static function Converts an array of string data into a comma separated string.
RowsOfMultiValueFields::renderCell public function