Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9.4 update #43

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Breadcrumb/IdcBreadcrumbBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,23 @@ public function applies(RouteMatchInterface $attributes) {
public function build(RouteMatchInterface $route_match) {

$nid = $route_match->getRawParameters()->get('node');
$node = $this->nodeStorage->load($nid);
$node = ($nid) ? $this->nodeStorage->load($nid) : NULL;
$breadcrumb = new Breadcrumb();

$breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
$breadcrumb->addLink(Link::createFromRoute($this->t('All collections'), 'idc-ui-module.collections'));

$chain = [];
$chain = array_filter($chain, function ($link) use ($nid) {
return $link !== $nid;
});

if (!empty($nid)) {
$this->walkMembership($node, $chain);
}

if (!$this->config->get('includeSelf')) {
array_pop($chain);
if ($this->config->get('includeSelf')) {
array_push($chain, $nid);
}

$breadcrumb->addCacheableDependency($node);
Expand Down
24 changes: 17 additions & 7 deletions src/Controller/CollectionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
namespace Drupal\idc_ui_module\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\file\Entity\File;
use Drupal\file\FileInterface;

class CollectionsController extends ControllerBase {
public function collections() {
Expand Down Expand Up @@ -39,9 +41,12 @@ public function collections() {
'field_media_of' => $collection_id,
'field_media_use' => array_values($thumbnail_taxonomy_term)[0]->id(),
]);

$thumbnail_id = array_values($media)[0]->thumbnail->target_id;

if (isset(array_values($media)[0]->thumbnail->target_id)) {
$thumbnail_id = array_values($media)[0]->thumbnail->target_id;
}
else {
$thumbnail_id = '';
}
$thumbnail = \Drupal::entityTypeManager()
->getStorage('file')
->load($thumbnail_id);
Expand All @@ -50,10 +55,10 @@ public function collections() {

if ($thumbnail) {
$image_url = $thumbnail->getFileUri();
$image_display_url = file_create_url($image_url);
$image_display_url = ($image_url) ? file_url_transform_relative(file_create_url($image_url)) : '';
}

$obj= (object) ['url' => $image_display_url, 'title' => $collection->get('title')->getString(), 'id' => $collection->id()];
$obj = (object) ['url' => $image_display_url, 'title' => $collection->get('title')->getString(), 'id' => $collection->id()];

array_push($featured_collections_array, $obj);
}
Expand All @@ -67,7 +72,7 @@ public function collections() {
];
}

public function collection(\Drupal\node\Entity\Node $collection) {
public static function collection(\Drupal\node\Entity\Node $collection) {
$featured_items = \Drupal::entityTypeManager()
->getListBuilder('node')
->getStorage()
Expand Down Expand Up @@ -105,6 +110,10 @@ public function collection(\Drupal\node\Entity\Node $collection) {
'field_media_use' => array_values($thumbnail_taxonomy_term)[0]->id()
]);

if (empty($media)) {
continue;
}

$thumbnail_id = array_values($media)[0]->thumbnail->target_id;

$thumbnail = \Drupal::entityTypeManager()
Expand All @@ -114,8 +123,9 @@ public function collection(\Drupal\node\Entity\Node $collection) {
$image_display_url = '';

if ($thumbnail) {
// @phpstan-ignore-next-line
$image_url = $thumbnail->getFileUri();
$image_display_url = file_create_url($image_url);
$image_display_url = ($image_url) ? file_url_transform_relative(file_create_url($image_url)) : '';
}

$obj = (object) ['url' => $image_display_url, 'title' => $item->get('title')->getString(), 'id' => $item->id()];
Expand Down