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

Refactor BlocksModule and create BlockApi. #2674

Merged
merged 1 commit into from
Dec 13, 2015
Merged
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ install:
# - sudo service apache2 restart
#
script:
- echo "Nothing to do.. yet!"
- phpunit
# - echo "Nothing to do.. yet!"
# - wget -dO - localhost/src
12 changes: 9 additions & 3 deletions CHANGELOG-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ CHANGELOG - ZIKULA 1.4.x
- Deprecated:
- n/a
- Fixes:
- n/a
- Fix module stylesheet not being loaded automatically for Core-2.0 modules.
- Features:
- n/a
- New advanced block filtering based on a combination of any query parameter or request attributes.
- Core-2.0 Features:
- n/a
- Implement new BlockApi and all corresponding methods.
- BlockControllerInterface
- AbstractBlockController
- Updated BlocksModule Admin UI.
- BlocksModule updated to Core-2.0 Spec.
- Added AbstractExtensionInstaller for use by third-party developers.
- Added ExtensionVariablesTrait for developers to insert into classes where Extension Variable management is needed.
- Vendor updates:
- Symfony updated to 2.8.0
- Font-Awesome updated to 4.5.0
Expand Down
43 changes: 43 additions & 0 deletions src/docs/Core-2.0/Blocks.md
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.
22 changes: 22 additions & 0 deletions src/docs/Core-2.0/Traits/ExtensionVariablesTrait.md
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.
21 changes: 21 additions & 0 deletions src/docs/Core-2.0/Traits/TranslatorTrait.md
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.
2 changes: 1 addition & 1 deletion src/lib/Zikula/Bundle/CoreBundle/Bundle/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function decode($file)
$json['autoload']['psr-4'][$ns] = $path;
}
$json['extra']['zikula']['short-name'] = substr($class, strrpos($class, '\\') + 1, strlen($class));
$json['extensionType'] = strpos($base, 'system') ? \ModUtil::TYPE_SYSTEM : \ModUtil::TYPE_MODULE;
$json['extensionType'] = false !== strpos($base, 'system') ? \ModUtil::TYPE_SYSTEM : \ModUtil::TYPE_MODULE;

return $json;
}
Expand Down
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'),
),
);
}
}
7 changes: 7 additions & 0 deletions src/lib/Zikula/Bundle/CoreBundle/Resources/config/theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<parameter key="zikula_core.internal.theme.default_page_var_setter_listener.class">Zikula\Bundle\CoreBundle\EventListener\Theme\DefaultPageVarSetterListener</parameter>
<parameter key="zikula_core.internal.theme.controller_annotation_reader_listener.class">Zikula\Bundle\CoreBundle\EventListener\Theme\ControllerAnnotationReaderListener</parameter>
<parameter key="zikula_core.internal.theme.template_path_override_listener.class">Zikula\Bundle\CoreBundle\EventListener\Theme\TemplatePathOverrideListener</parameter>
<parameter key="zikula_core.internal.theme.module_stylesheet_insert_listener.class">Zikula\Bundle\CoreBundle\EventListener\Theme\ModuleStylesheetInsertListener</parameter>
<parameter key="zikula_core.common.theme.assets.js.class">Zikula\Core\Theme\AssetBag</parameter>
<parameter key="zikula_core.common.theme.assets.css.class">Zikula\Core\Theme\AssetBag</parameter>
<parameter key="zikula_core.common.theme.assets.header.class">Zikula\Core\Theme\AssetBag</parameter>
Expand All @@ -35,6 +36,7 @@
<argument type="service" id="annotation_reader" />
<argument type="service" id="kernel" strict="false" />
<argument type="service" id="zikula_core.internal.theme_filter" />
<argument type="service" id="zikula_blocks_module.api.block" />
</service>

<service id="zikula_core.internal.theme.create_themed_response_listener" class="%zikula_core.internal.theme.create_themed_response_listener.class%">
Expand Down Expand Up @@ -74,6 +76,11 @@
<argument type="service" id="zikula_core.common.theme_engine" />
</service>

<service id="zikula_core.internal.theme.module_stylesheet_insert_listener" class="%zikula_core.internal.theme.module_stylesheet_insert_listener.class%">
<argument id="kernel" type="service"/>
<tag name="kernel.event_subscriber"/>
</service>

<service id="zikula_core.common.theme.assets_js" class="%zikula_core.common.theme.assets.js.class%" />
<service id="zikula_core.common.theme.assets_css" class="%zikula_core.common.theme.assets.css.class%" />
<service id="zikula_core.common.theme.assets_header" class="%zikula_core.common.theme.assets.header.class%" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Zikula\Bundle\CoreBundle\Twig;
use Zikula\Bundle\CoreBundle\Twig\Extension\SimpleFunction\AdminMenuPanelSimpleFunction;
use Zikula\Core\AbstractModule;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is not needed.

use Zikula\Core\Theme\AssetBag;

class CoreExtension extends \Twig_Extension
Expand Down Expand Up @@ -70,9 +71,6 @@ public function getFunctions()
new \Twig_SimpleFunction('icon', [$this, 'icon']),
new \Twig_SimpleFunction('lang', [$this, 'lang']),
new \Twig_SimpleFunction('langdirection', [$this, 'langDirection']),
new \Twig_SimpleFunction('showblockposition', [$this, 'showBlockPosition'], array('is_safe' => array('html'))),
new \Twig_SimpleFunction('showblock', [$this, 'showBlock']),
new \Twig_SimpleFunction('blockinfo', [$this, 'getBlockInfo']),
new \Twig_SimpleFunction('zasset', [$this, 'getAssetPath']),
new \Twig_SimpleFunction('showflashes', [$this, 'showFlashes'], array('is_safe' => array('html'))),
new \Twig_SimpleFunction('array_unset', [$this, 'arrayUnset']),
Expand Down Expand Up @@ -100,30 +98,6 @@ public function getAssetPath($path)
return $this->container->get('zikula_core.common.theme.asset_helper')->resolve($path);
}

public function showBlockPosition($name, $implode = true)
{
return \BlockUtil::displayPosition($name, false, $implode);
}

public function getBlockInfo($bid = 0, $name = null)
{
// get the block info array
$blockinfo = \BlockUtil::getBlockInfo($bid);

if ($name) {
return $blockinfo[$name];
}
}

public function showBlock($block, $blockname, $module)
{
if (!is_array($block)) {
$block = \BlockUtil::getBlockInfo($block);
}

return \BlockUtil::show($module, $blockname, $block);
}

/**
* Function to get the site's language.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Zikula\Bundle\CoreInstallerBundle\Controller;

use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -156,8 +157,23 @@ public function installModule($moduleName)
if (file_exists($bootstrap)) {
include_once $bootstrap;
}
$instance = new $className($this->container, $module);
if ($instance->install()) {

// support both Legacy and Core-2.0 Spec system modules until fully refactored.
// @todo remove legacy support when refactoring is complete.
$reflectionInstaller = new \ReflectionClass($className);
if ($reflectionInstaller->isSubclassOf('Zikula_AbstractInstaller')) {
$installer = $reflectionInstaller->newInstanceArgs(array($this->container, $module));
} elseif ($reflectionInstaller->isSubclassOf('\Zikula\Core\ExtensionInstallerInterface')) {
$installer = $reflectionInstaller->newInstance();
$installer->setBundle($module);
if ($installer instanceof ContainerAwareInterface) {
$installer->setContainer($this->container);
}
} else {
throw new \Exception('Installer class must be subclass of Zikula_AbstractInstaller or implement Zikula\Core\ExtensionInstallerInterface.');
}

if ($installer->install()) {

return true;
}
Expand Down Expand Up @@ -218,9 +234,10 @@ private function categorizeModules()

private function createBlocks()
{
$installer = new \Zikula\BlocksModule\BlocksModuleInstaller();
$installer->setBundle($this->container->get('kernel')->getModule('ZikulaBlocksModule'));
// create the default blocks.
$blockInstance = new \Zikula\BlocksModule\BlocksModuleInstaller($this->container, $this->container->get('kernel')->getModule('ZikulaBlocksModule'));
$blockInstance->defaultdata();
$installer->defaultdata();

return true;
}
Expand Down
Loading