-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5beae3b
Showing
14 changed files
with
1,260 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Kaliop\EzOptionFieldTypeBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
/** | ||
* This is the class that validates and merges configuration from your app/config files | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} | ||
*/ | ||
class Configuration implements ConfigurationInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('ez_systems_option_field_type'); | ||
|
||
// Here you should define the parameters that are allowed to | ||
// configure your bundle. See the documentation linked above for | ||
// more information on that topic. | ||
|
||
return $treeBuilder; | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace Kaliop\EzOptionFieldTypeBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
/** | ||
* This is the class that loads and manages your bundle configuration | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||
*/ | ||
class KaliopEzOptionFieldTypeExtension extends Extension implements PrependExtensionInterface | ||
{ | ||
// @see https://doc.ez.no/display/EZP/Template+implementation | ||
public function prepend(ContainerBuilder $container) | ||
{ | ||
$config = Yaml::parse(__DIR__ . '/../Resources/config/ez_field_templates.yml'); | ||
$container->prependExtensionConfig('ezpublish', $config); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.yml'); | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace Kaliop\EzOptionFieldTypeBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class KaliopEzOptionFieldTypeBundle extends Bundle | ||
{ | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,18 @@ | ||
KaliopEzOptionFieldTypeBundle | ||
================== | ||
|
||
Introduction | ||
------------ | ||
|
||
This bundle provides eZOption field type for eZPlatform. | ||
|
||
Documentation | ||
------------- | ||
|
||
Usage examples can be found [here](USAGE.md). | ||
|
||
License | ||
------- | ||
|
||
This bundle is released under the MIT license. See the included | ||
[LICENSE](LICENSE) file for more information. |
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,4 @@ | ||
system: | ||
default: | ||
field_templates: | ||
- {template: KaliopEzOptionFieldTypeBundle:fields:ezoption.html.twig, priority: 10} |
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,18 @@ | ||
services: | ||
# ez_systems_option_field_type.example: | ||
# class: Kaliop\EzOptionFieldTypeBundle\Example | ||
# arguments: [@service_id, "plain_value", %parameter%] | ||
|
||
# override ezpublish.fieldType.ezoption in vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/settings/fieldtypes.yml | ||
ezpublish.fieldType.ezoption: | ||
class: Kaliop\EzOptionFieldTypeBundle\eZ\Publish\FieldType\Option\Type | ||
parent: ezpublish.fieldType | ||
arguments: [ "ezoption" ] | ||
tags: | ||
- { name: ezpublish.fieldType, alias: ezoption } | ||
|
||
# override ezpublish.fieldType.ezoption.converter in vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/settings/storage_engines/legacy/field_value_converters.yml | ||
ezpublish.fieldType.ezoption.converter: | ||
class: Kaliop\EzOptionFieldTypeBundle\eZ\Publish\FieldType\Option\OptionConverter | ||
tags: | ||
- { name: ezpublish.storageEngine.legacy.converter, alias: ezoption } |
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,25 @@ | ||
{% extends "EzPublishCoreBundle::content_fields.html.twig" %} | ||
|
||
{% block ezoption_field %} | ||
{# Parameters (not required) for this type field template : #} | ||
{# - classes : add classes to div tag container #} | ||
{# - name : name of select #} | ||
{# - selected : id of item that is select #} | ||
{# - add_empty_option : if true add in first position of #} | ||
{# select an empty option #} | ||
{% spaceless %} | ||
<div class="ezoption{% if classes is defined %} {{ classes }}{% endif %}"> | ||
<label class="ezoption--name"{% if name is defined %} for="{{ name }}"{% endif %}>{{ field.value.name }}</label> | ||
<select {% if name is defined %}name="{{ name }}"{% endif %} class="ezoption--options"> | ||
{% if add_empty_option is defined and add_empty_option %} | ||
<option value=""></option> | ||
{% endif %} | ||
{% for option in field.value.options %} | ||
<option value="{{ option.id }}" | ||
{% if selected is defined and | ||
selected == option.id %}selected{% endif %}>{{ option.text }}{% if option.additionalPrice is not empty %} - {{ option.additionalPrice }}{% endif %}</option> | ||
{% endfor %} | ||
</select> | ||
</div> | ||
{% endspaceless %} | ||
{% endblock %} |
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,73 @@ | ||
Usage | ||
================== | ||
|
||
Save an ez_option value in eZ Publish 5 | ||
------------ | ||
```php | ||
<?php | ||
|
||
use Kaliop\EzOptionFieldTypeBundle\eZ\Publish\FieldType\Option; | ||
|
||
// Get service | ||
$repository = $this->getContainer()->get('ezpublish.api.repository'); | ||
$userService = $repository->getUserService(); | ||
$contentService = $repository->getContentService(); | ||
$locationService = $repository->getLocationService(); | ||
$contentTypeService = $repository->getContentTypeService(); | ||
|
||
// Identifying to the repository with a login and a password | ||
$user = $userService->loadUserByLogin($login); | ||
$repository->setCurrentUser($user); | ||
|
||
// The ContentCreateStruct | ||
$contentType = $contentTypeService->loadContentTypeByIdentifier('survey'); | ||
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); | ||
|
||
// Create ez option | ||
$option = new Option\Value(); | ||
$option->setName('Question - saved in eZ 5'); | ||
$option->addOption('test-1'); // same as $option->addOption(new Option\OptionElement('test-1')); // id = -1 -> 0 | ||
$option->addOption(new Option\OptionElement('test-2')); // id = -1 -> 1 | ||
$option->addOption(new Option\OptionElement('test-3', null, 1000)); // id = 1000 -> 1000 | ||
$option->addOption(new Option\OptionElement('test-4', 10)); // id = -1 -> 1001 | ||
$option->addOption(new Option\OptionElement('test-5', 20, 5)); // id = 5 -> 5 | ||
|
||
/* | ||
It is equivalent to this code : | ||
$options = array( | ||
'test-1', | ||
new Option\OptionElement('test-2'), | ||
new Option\OptionElement('test-3', null, 1000), | ||
new Option\OptionElement('test-4', 10), | ||
new Option\OptionElement('test-5', 20, 5), | ||
); | ||
$option = new Option\Value('Question - saved in eZ 5', $options); | ||
|
||
or | ||
|
||
$options = array( | ||
'test-1', | ||
'test-2', | ||
); | ||
$option = new Option\Value('Question - saved in eZ 5', $options); | ||
$options = array( | ||
new Option\OptionElement('test-3', null, 1000), | ||
new Option\OptionElement('test-4', 10), | ||
new Option\OptionElement('test-5', 20, 5), | ||
); | ||
$option->addOptions($options); | ||
*/ | ||
|
||
// Setting the fields values | ||
$contentCreateStruct->setField('expiry', new \DateTime()); | ||
$contentCreateStruct->setField('question_answers', $option); | ||
|
||
// Setting the Location | ||
$locationCreateStruct = $locationService->newLocationCreateStruct(274); | ||
|
||
// Creating and publishing | ||
$draft = $contentService->createContent($contentCreateStruct, array( $locationCreateStruct )); | ||
$content = $contentService->publishVersion($draft->versionInfo); | ||
|
||
``` | ||
|
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,19 @@ | ||
{ | ||
"name": "kaliop/ezoptionfieldtypebundle", | ||
"description": "EzOption FieldType for eZ Publish Platform", | ||
"license": "GPL-2.0", | ||
"keywords": ["ezpublish", "ezoption"], | ||
"authors": [ | ||
{ | ||
"name": "Kaliop", | ||
"homepage": "http://www.kaliop.com/" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.3", | ||
"ezsystems/ezpublish-kernel": "~5.3 | >=2014.03" | ||
}, | ||
"autoload": { | ||
"psr-4": {"Kaliop\\EzOptionFieldTypeBundle\\": ""} | ||
} | ||
} |
Oops, something went wrong.