You are here

protected function Book::getEntry in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  2. 8 modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  3. 8.2 modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  4. 8.3 modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  5. 8.4 modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  6. 8.5 modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  7. 8.6 modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  8. 8.7 modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  9. 8.8 modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  10. 10.3.x modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  11. 10.0.x modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()
  12. 10.1.x modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::getEntry()

Makes an array with data of an entity.

Parameters

array $item: Array with items.

Return value

array Returns an array.

Overrides DemoNode::getEntry

File

modules/custom/social_demo/src/Plugin/DemoContent/Book.php, line 59

Class

Book
Book Plugin for demo content.

Namespace

Drupal\social_demo\Plugin\DemoContent

Code

protected function getEntry(array $item) {
  $entry = parent::getEntry($item);
  $entry['field_content_visibility'] = $item['field_content_visibility'];

  // Load image by uuid and set to node.
  if (!empty($item['field_book_image'])) {
    $entry['field_book_image'] = $this
      ->prepareImage($item['image'], $item['image_alt']);
  }

  // Load attachments to node.
  if (!empty($item['field_files'])) {
    $entry['field_files'] = $this
      ->prepareAttachment($item['field_files']);
  }
  if (!empty($item['alias'])) {
    $entry['path'] = [
      'alias' => $item['alias'],
    ];
  }
  if (!empty($item['book'])) {

    // Top level book.
    if ($item['book']['id'] === $item['uuid']) {
      $entry['book']['bid'] = 'new';
      unset($entry['book']['id']);
    }
    $mainbook = $this->entityStorage
      ->loadByProperties([
      'uuid' => $item['book']['id'],
    ]);
    $mainbook = current($mainbook);

    // Must be a valid node.
    if ($mainbook instanceof Node) {
      $entry['book']['bid'] = $mainbook
        ->id();
      $entry['book']['weight'] = $item['book']['weight'];
      unset($entry['book']['id']);
      if (isset($item['book']['parent'])) {
        $parentbook = $this->entityStorage
          ->loadByProperties([
          'uuid' => $item['book']['parent'],
        ]);
        $parentbook = current($parentbook);
        if ($parentbook instanceof Node) {
          $entry['book']['pid'] = $parentbook
            ->id();
        }
      }
      else {
        $entry['book']['pid'] = $mainbook
          ->id();
      }
    }
  }
  return $entry;
}