Skip to content
This repository was archived by the owner on Aug 13, 2022. It is now read-only.

Commit 4cc51a1

Browse files
committed
added support for needles in MultiHook 6.0.0
1 parent 0de10d7 commit 4cc51a1

File tree

11 files changed

+286
-4
lines changed

11 files changed

+286
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ New features:
142142
- Added several options to author information plugin (#298).
143143
- Added missing filter hook calls.
144144
- Added new setting for automatic linking of page titles using MultiHook (#335).
145+
- Added MultiHook needle.
145146

146147
Bugfixes:
147148
- Minor fixes for external display (#332).

src/modules/Zikula/ContentModule/Base/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
77
* @author Axel Guckelsberger <[email protected]>.
88
* @link https://ziku.la
9-
* @version Generated by ModuleStudio 1.4.0 (https://modulestudio.de) at Sun Mar 03 18:43:15 CET 2019.
9+
* @version Generated by ModuleStudio 1.4.0 (https://modulestudio.de) at Mon Mar 04 08:10:46 CET 2019.
1010
*/
1111

1212
/**
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
<?php
2+
/**
3+
* Content.
4+
*
5+
* @copyright Axel Guckelsberger (Zikula)
6+
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7+
* @author Axel Guckelsberger <[email protected]>.
8+
* @link https://ziku.la
9+
* @version Generated by ModuleStudio 1.4.0 (https://modulestudio.de).
10+
*/
11+
12+
namespace Zikula\ContentModule\Needle\Base;
13+
14+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
15+
use Symfony\Component\Routing\RouterInterface;
16+
use Zikula\Common\Translator\TranslatorInterface;
17+
use Zikula\ContentModule\Entity\Factory\EntityFactory;
18+
use Zikula\ContentModule\Helper\EntityDisplayHelper;
19+
use Zikula\ContentModule\Helper\PermissionHelper;
20+
21+
/**
22+
* PageNeedle base class.
23+
*/
24+
abstract class AbstractPageNeedle
25+
{
26+
/**
27+
* Translator instance
28+
*
29+
* @var TranslatorInterface
30+
*/
31+
protected $translator;
32+
33+
/**
34+
* @var RouterInterface
35+
*/
36+
protected $router;
37+
38+
/**
39+
* @var PermissionHelper
40+
*/
41+
protected $permissionHelper;
42+
43+
/**
44+
* @var EntityFactory
45+
*/
46+
protected $entityFactory;
47+
48+
/**
49+
* @var EntityDisplayHelper
50+
*/
51+
protected $entityDisplayHelper;
52+
53+
/**
54+
* Bundle name
55+
*
56+
* @var string
57+
*/
58+
protected $bundleName;
59+
60+
/**
61+
* The name of this needle
62+
*
63+
* @var string
64+
*/
65+
protected $name;
66+
67+
/**
68+
* PageNeedle constructor.
69+
*
70+
* @param TranslatorInterface $translator
71+
* @param RouterInterface $router
72+
* @param PermissionHelper $permissionHelper
73+
* @param EntityFactory $entityFactory
74+
* @param EntityDisplayHelper $entityDisplayHelper
75+
*/
76+
public function __construct(
77+
TranslatorInterface $translator,
78+
RouterInterface $router,
79+
PermissionHelper $permissionHelper,
80+
EntityFactory $entityFactory,
81+
EntityDisplayHelper $entityDisplayHelper
82+
) {
83+
$this->translator = $translator;
84+
$this->router = $router;
85+
$this->permissionHelper = $permissionHelper;
86+
$this->entityFactory = $entityFactory;
87+
$this->entityDisplayHelper = $entityDisplayHelper;
88+
89+
$nsParts = explode('\\', get_class($this));
90+
$vendor = $nsParts[0];
91+
$nameAndType = $nsParts[1];
92+
93+
$this->bundleName = $vendor . $nameAndType;
94+
$this->name = str_replace('Needle', '', array_pop($nsParts));
95+
}
96+
97+
/**
98+
* Returns the bundle name.
99+
*
100+
* @return string
101+
*/
102+
public function getBundleName()
103+
{
104+
return $this->bundleName;
105+
}
106+
107+
/**
108+
* Returns the name of this needle.
109+
*
110+
* @return string
111+
*/
112+
public function getName()
113+
{
114+
return $this->name;
115+
}
116+
117+
/**
118+
* Returns the icon name (FontAwesome icon code suffix, e.g. "pencil").
119+
*
120+
* @return string
121+
*/
122+
public function getIcon()
123+
{
124+
return 'circle-o';
125+
}
126+
127+
/**
128+
* Returns the title of this needle.
129+
*
130+
* @return string
131+
*/
132+
public function getTitle()
133+
{
134+
return $this->translator->__('Pages', 'zikulacontentmodule');
135+
}
136+
137+
/**
138+
* Returns the description of this needle.
139+
*
140+
* @return string
141+
*/
142+
public function getDescription()
143+
{
144+
return $this->translator->__('Links to the list of pages and specific pages.', 'zikulacontentmodule');
145+
}
146+
147+
/**
148+
* Returns usage information shown on settings page.
149+
*
150+
* @return string
151+
*/
152+
public function getUsageInfo()
153+
{
154+
return 'CONTENT{PAGES|PAGE-pageId}';
155+
}
156+
157+
/**
158+
* Returns whether this needle is active or not.
159+
*
160+
* @return boolean
161+
*/
162+
public function isActive()
163+
{
164+
return true;
165+
}
166+
167+
/**
168+
* Returns whether this needle is case sensitive or not.
169+
*
170+
* @return boolean
171+
*/
172+
public function isCaseSensitive()
173+
{
174+
return true;
175+
}
176+
177+
/**
178+
* Returns the needle subject entries.
179+
*
180+
* @return string[]
181+
*/
182+
public function getSubjects()
183+
{
184+
return ['CONTENTPAGES', 'CONTENTPAGE-'];
185+
}
186+
187+
/**
188+
* Applies the needle functionality.
189+
*
190+
* @param string $needleId
191+
* @param string $needleText
192+
*
193+
* @return string Replaced value for the needle
194+
*/
195+
public function apply($needleId, $needleText)
196+
{
197+
// cache the results
198+
static $cache;
199+
if (!isset($cache)) {
200+
$cache = [];
201+
}
202+
203+
if (isset($cache[$needleId])) {
204+
// needle is already in cache array
205+
return $cache[$needleId];
206+
}
207+
208+
// strip application prefix from needle
209+
$needleText = str_replace('CONTENT', '', $needleText);
210+
211+
if ('PAGES' == $needleText) {
212+
if (!$this->permissionHelper->hasComponentPermission('page', ACCESS_READ)) {
213+
$cache[$needleId] = '';
214+
} else {
215+
$cache[$needleId] = '<a href="' . $this->router->generate('zikulacontentmodule_page_view', [], UrlGeneratorInterface::ABSOLUTE_URL) . '" title="' . $this->translator->__('View pages', 'zikulacontentmodule') . '">' . $this->translator->__('Pages', 'zikulacontentmodule') . '</a>';
216+
}
217+
218+
return $cache[$needleId];
219+
}
220+
221+
$entityId = intval($needleId);
222+
if (!$entityId) {
223+
$cache[$needleId] = '';
224+
225+
return $cache[$needleId];
226+
}
227+
228+
$repository = $this->entityFactory->getRepository('page');
229+
$entity = $repository->selectById($entityId, false);
230+
if (null === $entity) {
231+
$cache[$needleId] = '<em>' . $this->translator->__f('Page with id %id% could not be found', ['%id%' => $entityId], 'zikulacontentmodule') . '</em>';
232+
233+
return $cache[$needleId];
234+
}
235+
236+
if (!$this->permissionHelper->mayRead($entity)) {
237+
$cache[$needleId] = '';
238+
239+
return $cache[$needleId];
240+
}
241+
242+
$title = $this->entityDisplayHelper->getFormattedTitle($entity);
243+
$cache[$needleId] = '<a href="' . $this->router->generate('zikulacontentmodule_page_display', $entity->createUrlArgs(), UrlGeneratorInterface::ABSOLUTE_URL) . '" title="' . str_replace('"', '', $title) . '">' . $title . '</a>';
244+
245+
return $cache[$needleId];
246+
}
247+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Content.
4+
*
5+
* @copyright Axel Guckelsberger (Zikula)
6+
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7+
* @author Axel Guckelsberger <[email protected]>.
8+
* @link https://ziku.la
9+
* @version Generated by ModuleStudio 1.4.0 (https://modulestudio.de).
10+
*/
11+
12+
namespace Zikula\ContentModule\Needle;
13+
14+
use Zikula\ContentModule\Needle\Base\AbstractPageNeedle;
15+
16+
/**
17+
* PageNeedle implementation class.
18+
*/
19+
class PageNeedle extends AbstractPageNeedle
20+
{
21+
// feel free to extend the needle here
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
zikula_content_module.multihook_needle.page:
3+
class: Zikula\ContentModule\Needle\PageNeedle
4+
arguments:
5+
- '@translator.default'
6+
- '@router'
7+
- '@zikula_content_module.permission_helper'
8+
- '@zikula_content_module.entity_factory'
9+
- '@zikula_content_module.entity_display_helper'
10+
tags: ['zikula.multihook_needle']

src/modules/Zikula/ContentModule/Resources/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ imports:
88
- { resource: 'forms.yml' }
99
- { resource: 'helpers.yml' }
1010
- { resource: 'hooks.yml' }
11+
- { resource: 'needles.yml' }
1112
- { resource: 'twig.yml' }
1213
- { resource: 'logger.yml' }
1314
- { resource: 'customServices.yml' }

src/modules/Zikula/ContentModule/Resources/docs/model/Content.mostapp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ application "Content" {
99
amountOfExampleRows 1
1010
generateListContentType false
1111
generateDetailContentType false
12+
generateMultiHookNeedles true
1213
generateRssTemplates false
1314
generateAtomTemplates false
1415
generateKmlTemplates false
2.39 KB
Loading

src/modules/Zikula/ContentModule/Resources/docs/model/structure_de.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ <h2><i class="fa fa-puzzle-piece"></i> Integrationseinstellungen</h2>
20362036
<td headers="hSettingValue1" class="text-center"><i class="fa fa-check"></i>
20372037
</td>
20382038
<td headers="hSettingName2">MultiHook Needles</td>
2039-
<td headers="hSettingValue2" class="text-center"><i class="fa fa-times"></i>
2039+
<td headers="hSettingValue2" class="text-center"><i class="fa fa-check"></i>
20402040
</td>
20412041
</tr>
20422042
<tr>

src/modules/Zikula/ContentModule/Resources/docs/model/structure_en.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ <h2><i class="fa fa-puzzle-piece"></i> Integration settings</h2>
20362036
<td headers="hSettingValue1" class="text-center"><i class="fa fa-check"></i>
20372037
</td>
20382038
<td headers="hSettingName2">MultiHook needles</td>
2039-
<td headers="hSettingValue2" class="text-center"><i class="fa fa-times"></i>
2039+
<td headers="hSettingValue2" class="text-center"><i class="fa fa-check"></i>
20402040
</td>
20412041
</tr>
20422042
<tr>

0 commit comments

Comments
 (0)