Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Added built-in support for IvoryCKEditorBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Sep 2, 2015
1 parent 22df423 commit 601c2ba
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 2 deletions.
13 changes: 12 additions & 1 deletion Admin/StaticContentAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class StaticContentAdmin extends Admin
{
protected $translationDomain = 'CmfContentBundle';

private $ivoryCkeditor = array();

public function setIvoryCkeditor($config)
{
$this->ivoryCkeditor = (array) $config;
}

public function getExportFormats()
{
return array();
Expand All @@ -42,7 +49,11 @@ protected function configureFormFields(FormMapper $formMapper)
->add('parent', 'doctrine_phpcr_odm_tree', array('root_node' => $this->getRootPath(), 'choice_list' => array(), 'select_root_node' => true))
->add('name', 'text')
->add('title', 'text')
->add('body', 'textarea')
->add(
'body',
$this->ivoryCkeditor ? 'ckeditor' : 'textarea',
$this->ivoryCkeditor
)
->end()
;
}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
=========

* **2015-08-31**: Added IvoryCKEditorBundle integration and added the
`ivory_ckeditor` settings.

1.2.0-RC1
---------

Expand Down
30 changes: 30 additions & 0 deletions DependencyInjection/CmfContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,38 @@ public function load(array $configs, ContainerBuilder $container)
if (isset($config['default_template'])) {
$container->setParameter($this->getAlias() . '.default_template', $config['default_template']);
}

$this->loadIvoryCKEditor($config['ivory_ckeditor'], $container);
}

protected function loadIvoryCKEditor(array $config, ContainerBuilder $container)
{
$container->setParameter($this->getAlias() . '.ivory_ckeditor.config', array());

$bundles = $container->getParameter('kernel.bundles');
if ('auto' === $config['enabled'] && !isset($bundles['IvoryCKEditorBundle'])) {
return;
}

if (true === $config['enabled'] && !isset($bundles['IvoryCKEditorBundle'])) {
$message = 'IvoryCKEditorBundle integration was explicitely enabled, but the bundle is not available';

if (class_exists('Ivory\CKEditorBundle\IvoryCKEditorBundle')) {
$message .= ' (did you forget to register the bundle in the AppKernel?)';
}

throw new \LogicException($message.'.');
}

if (false === $config['enabled'] || !isset($bundles['IvoryCKEditorBundle'])) {
return;
}

$container->setParameter($this->getAlias() . '.ivory_ckeditor.config', array(
'config_name' => $config['config_name'],
));
}

public function loadPhpcr($config, XmlFileLoader $loader, ContainerBuilder $container)
{
$container->setParameter($this->getAlias() . '.backend_type_phpcr', true);
Expand Down
13 changes: 13 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->arrayNode('ivory_ckeditor')
->addDefaultsIfNotSet()
->treatFalseLike(array('enabled' => false))
->treatTrueLike(array('enabled' => true))
->treatNullLike(array('enabled' => 'auto'))
->children()
->enumNode('enabled')
->values(array(true, false, 'auto'))
->defaultValue('auto')
->end()
->scalarNode('config_name')->defaultValue('cmf_simple_cms')->end()
->end()
->end()
->end()
;

Expand Down
4 changes: 4 additions & 0 deletions Resources/config/admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<call method="setRootPath">
<argument>%cmf_content.persistence.phpcr.content_basepath%</argument>
</call>

<call method="setIvoryCkeditor">
<argument>%cmf_content.ivory_ckeditor.config%</argument>
</call>
</service>
</services>
</container>
6 changes: 6 additions & 0 deletions Resources/config/schema/content-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
<xsd:complexType name="config">
<xsd:sequence>
<xsd:element name="persistence" type="persistence" minOccurs="0" />
<xsd:element name="ivory-ckeditor" type="ivory_ckeditor" minOccurs="0" />
</xsd:sequence>

<xsd:attribute name="default-template" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="ivory_ckeditor">
<xsd:attribute name="enabled" type="enable_auto" />
<xsd:attribute name="config-name" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="persistence">
<xsd:sequence>
<xsd:element name="phpcr" type="phpcr" minOccurs="1" />
Expand Down
2 changes: 2 additions & 0 deletions Tests/Resources/Fixtures/config/config2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
use-sonata-admin="auto"
/>
</persistence>

<ivory-ckeditor config-name="my_custom_toolbar"/>
</config>
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"friendsofsymfony/rest-bundle": "Improved handling for different output formats",
"doctrine/phpcr-odm": "To persist content with the PHP content repository",
"doctrine/phpcr-bundle": "To integrate PHPCR-ODM with Symfony",
"sonata-project/doctrine-phpcr-admin-bundle": "To provide admin interfaces for the content"
"sonata-project/doctrine-phpcr-admin-bundle": "To provide admin interfaces for the content (~1.1)",
"ivory/ckeditor-bundle": "to provide a CKEditor in the admin interface"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 601c2ba

Please sign in to comment.