You are here

public function Presentation::toJSON in Isotope (with Masonry and Packery) 8

Convert a presentation into a JSON representation.

Style as per http://isotope.metafizzy.co/#initialize-in-html.

File

src/Entity/Presentation.php, line 111
Contains \Drupal\isotope\Entity\Presentation.

Class

Presentation
Defines a Presentation configuration entity.

Namespace

Drupal\isotope\Entity

Code

public function toJSON(array $additional_attributes = []) {

  // Properties that should be passed directly to isotope.
  $allowed_attributes = [
    'layoutMode',
    'transitionDuration',
    'urlFilters',
    'isFitWidth',
    'isHorizontal',
    'stamp',
    'horizontalAlignment',
    'verticalAlignment',
    'isOriginLeft',
  ];

  // Default attributes.
  $attributes = [
    'columnWidth' => '.js-isotope-grid-sizer',
    'itemSelector' => '.js-isotope-element',
    'gutter' => '.js-isotope-gutter-sizer',
  ] + $additional_attributes;
  foreach ($this as $key => $value) {
    if (!empty($value)) {
      $key = IsotopeController::snakeToCamel($key);
      if (in_array($key, $allowed_attributes)) {
        $attributes[$key] = $value;
      }
    }
  }
  return Json::encode($attributes);
}