Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
FeaturedPostsCell
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 display
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2declare(strict_types=1);
3
4namespace DefaultTheme\View\Cell;
5
6use Cake\View\Cell;
7
8/**
9 * FeaturedPosts cell
10 *
11 * Displays featured articles in sidebar or other locations
12 */
13class FeaturedPostsCell extends Cell
14{
15    /**
16     * List of valid options that can be passed into this
17     * cell's constructor.
18     *
19     * @var array<string>
20     */
21    protected array $_validCellOptions = ['cacheKey', 'title'];
22
23    /**
24     * Default display method
25     *
26     * Fetches and displays featured articles
27     *
28     * @param string|null $cacheKey Optional cache key for performance
29     * @param string|null $title Optional custom title for the section
30     * @return void
31     */
32    public function display(?string $cacheKey = null, ?string $title = null): void
33    {
34        $articlesTable = $this->fetchTable('Articles');
35
36        // Generate cache key if not provided
37        if ($cacheKey === null) {
38            $lang = $this->request->getParam('lang', 'en');
39            $cacheKey = 'featured_' . $lang . '_';
40        }
41
42        $articles = $articlesTable->getFeatured($cacheKey);
43
44        $this->set('articles', $articles);
45        $this->set('title', $title ?? __('Featured posts'));
46    }
47}