-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2674 from zikula/BlockApi
Refactor BlocksModule and create BlockApi.
- Loading branch information
Showing
120 changed files
with
4,607 additions
and
2,556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Blocks | ||
====== | ||
|
||
- Block classnames should be suffixed by `Block` and located in the `ModuleRoot/Block/` directory. | ||
- Block classes must implement Zikula\Core\BlockControllerInterface. | ||
- Zikula\Core\Controller\AbstractBlockController is available if desired. | ||
- Blocks must register their PermissionSchema as part of the owning module's array (in composer.json) | ||
- The old "info" array of the block has been eliminated. | ||
- `module` is inferred from providing module. | ||
- `text_type` is replaced by `getType()`. | ||
- `allow_multiple` is always `true`. | ||
- `form_content` is no longer allowed (blocks MUST implement their own content control). | ||
- The `init` method has been eliminated. | ||
- `$content` parameter in both the `modify` and `display` method is un-serialized content property from BlockEntity. | ||
- The `modify` method is expected to handle both the form and processing of the form (like a typical entity controller). | ||
- The modify method _should_ implement a symfony form handling the data as an array. | ||
- A simple Twig template is available as a default `ZikulaBlocksModule:Block:default_modify.html.twig`. | ||
- if you implement your own modify template, **do not** render the `form_start(form)` or `form_end(form)` | ||
tags within your template. | ||
|
||
|
||
Block as a Service | ||
------------------ | ||
|
||
Registering your block class as a service is optional, but can provide greater flexibility with dependencies. If a class | ||
simply extends `AbstractBlockController`, it is not required to register the class as a service. Additionally, if a | ||
class implements `BlockControllerInterface` and requires no construction arguments, registering as a service is | ||
not required. | ||
|
||
If you choose to register your block as a service, you must tag your block service with the following tag: | ||
|
||
<tag name="zikula.block" module="<CommonModuleName>" /> | ||
|
||
The 'CommonModuleName' is the 'camel-cased' bundle name. | ||
|
||
|
||
Block Filters | ||
------------- | ||
|
||
A powerful new filter mechanism has been implemented for blocks. For any block you can set up your own filters based on | ||
nearly any request attribute or query parameter. These can also be used in any combination. As long as all | ||
filter conditions evaluate to **true** the block will be displayed. Conditions can be compared using any available | ||
comparator: not just `==`, but `!=`, `in_array()` and others. Array values must be a comma-delimited string. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
ExtensionVariablesTrait | ||
======================= | ||
|
||
name: \Zikula\ExtensionsModule\ExtensionVariablesTrait | ||
|
||
Adds the following methods to your class: | ||
|
||
- getVar($variableName, $default = false) | ||
- getVars() | ||
- setVar($variableName, $value = '') | ||
- setVars(array $variables) | ||
- delVar($variableName) | ||
- delVars() | ||
|
||
In your constructor, you are required to set the following properties included in the trait: | ||
|
||
- $variableApi | ||
- Must be set to the "zikula_extensions_module.api.variable" service | ||
- $extensionName | ||
- Must be set to the "common name" of the extension (e.g. "ZikulaBlocksModule") | ||
|
||
See \Zikula\Core\AbstractExtensionInstaller for usage example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
TranslatorTrait | ||
=============== | ||
|
||
name: \Zikula\Common\Translator\TranslatorTrait | ||
|
||
Adds the following methods to your class: | ||
|
||
- \__($msg, $domain = null, $locale = null) | ||
- _n($m1, $m2, $n, $domain = null, $locale = null) | ||
- \__f($msg, $param, $domain = null, $locale = null) | ||
- _fn($m1, $m2, $n, $param, $domain = null, $locale = null) | ||
- getTranslator() | ||
|
||
_note: if you are reading this unrendered, the slash characters above are not part of the method name. they are escape | ||
characters for the renderer._ | ||
|
||
You are required to implement a public method `setTranslator($translator)`. | ||
In your constructor, you are required to call the `setTranslator()` method and set the `$translator` property. | ||
Typically this will be set to the `'translator'` service. | ||
|
||
See \Zikula\Core\AbstractExtensionInstaller for usage example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/lib/Zikula/Bundle/CoreBundle/EventListener/Theme/ModuleStylesheetInsertListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/*** Copyright Zikula Foundation 2015 - Zikula Application Framework | ||
* | ||
* This work is contributed to the Zikula Foundation under one or more | ||
* Contributor Agreements and licensed to You under the following license: | ||
* | ||
* @license GNU/LGPLv3 (or at your option, any later version). | ||
* | ||
* Please see the NOTICE file distributed with this source code for further | ||
* information regarding copyright and licensing. | ||
*/ | ||
|
||
namespace Zikula\Bundle\CoreBundle\EventListener\Theme; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Zikula\Core\Controller\AbstractController; | ||
|
||
/** | ||
* Class ModuleStylesheetInsertListener | ||
* @package Zikula\Bundle\CoreBundle\EventListener\Theme | ||
*/ | ||
class ModuleStylesheetInsertListener implements EventSubscriberInterface | ||
{ | ||
private $kernel; | ||
|
||
public function __construct(KernelInterface $kernel) | ||
{ | ||
$this->kernel = $kernel; | ||
} | ||
|
||
/** | ||
* Add the module stylesheet to the page assets. | ||
* @param FilterControllerEvent $event | ||
* @throws \Twig_Error_Loader | ||
*/ | ||
public function insertModuleStylesheet(FilterControllerEvent $event) | ||
{ | ||
if (!$event->isMasterRequest()) { | ||
return; | ||
} | ||
$controller = $event->getController()[0]; | ||
if ($controller instanceof AbstractController) { | ||
$module = $this->kernel->getModule($controller->getName()); | ||
$module->addStylesheet(); | ||
} | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return array( | ||
KernelEvents::CONTROLLER => array( | ||
array('insertModuleStylesheet'), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.