You are here

class JSONViews in JSON Field 8

Class JSONViews.

@package Drupal\json_field

Hierarchy

Expanded class hierarchy of JSONViews

1 string reference to 'JSONViews'
json_field.services.yml in ./json_field.services.yml
json_field.services.yml
1 service uses JSONViews
json_field.views in ./json_field.services.yml
Drupal\json_field\JSONViews

File

src/JSONViews.php, line 13

Namespace

Drupal\json_field
View source
class JSONViews implements JSONViewsInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function getViewsFieldData(FieldStorageConfigInterface $field_storage) {

    // Make sure views.views.inc is loaded.
    module_load_include('inc', 'views', 'views.views');

    // Get the default data from the views module.
    $data = views_field_default_views_data($field_storage);
    $field_name = $field_storage
      ->getName();
    $value_field_name = $field_name . '_value';
    $entity_entry = $field_storage
      ->getTargetEntityTypeId() . '__' . $field_name;
    if (!empty($data[$entity_entry][$value_field_name])) {
      $data[$entity_entry][$field_name . '_json_value'] = [
        'group' => $data[$entity_entry][$value_field_name]['group'],
        'title' => $this
          ->t('@value_title (data)', [
          '@value_title' => $data[$entity_entry][$value_field_name]['title'],
        ]),
        'title short' => $data[$entity_entry][$value_field_name]['title short'],
        'help' => $data[$entity_entry][$value_field_name]['help'],
        'field' => $data[$entity_entry][$field_name]['field'],
      ];
      $data[$entity_entry][$field_name . '_json_value']['field']['id'] = 'json_data';
    }
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JSONViews::getViewsFieldData public function Gets the views data for a field instance. Overrides JSONViewsInterface::getViewsFieldData
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.