Skip to content

Commit

Permalink
Bugfix for #215
Browse files Browse the repository at this point in the history
Implements a event for adding alls MCW fields to the DCA. This should solve a problem with the fileTree Widget or the pageTree widget.

Moved the Event GetOptionsEvent to another folder. Add a new GetOptionsEvent Class under the MCW namespace. Mark the GetOptionsEvent in the MAW namespace as deprecated.
  • Loading branch information
stefanheimes committed Jun 5, 2017
1 parent 80d78a9 commit 747bdc7
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 7 deletions.
2 changes: 2 additions & 0 deletions system/modules/multicolumnwizard/MultiColumnWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ public function generate()

foreach ($this->columnFields as $strKey => $arrField)
{
$fullName = $this->strName . '__' . $strKey;

// Store unique fields
if ($arrField['eval']['unique'])
{
Expand Down
16 changes: 10 additions & 6 deletions system/modules/multicolumnwizard/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@

/**
* Contao Open Source CMS
*
*
* Copyright (C) 2005-2013 Leo Feyer
*
*
* @package Multicolumnwizard
* @link https://contao.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL
*/


/**
* Register the classes
*/
ClassLoader::addClasses(array
(
'MultiColumnWizardHelper' => 'system/modules/multicolumnwizard/MultiColumnWizardHelper.php',
'MultiColumnWizard' => 'system/modules/multicolumnwizard/MultiColumnWizard.php',
'MenAtWork\MultiColumnWizard\Event\GetOptionsEvent' => 'system/modules/multicolumnwizard/src/Event/GetOptionsEvent.php',
// Basic classes.
'MultiColumnWizardHelper' => 'system/modules/multicolumnwizard/MultiColumnWizardHelper.php',
'MultiColumnWizard' => 'system/modules/multicolumnwizard/MultiColumnWizard.php',
// Src Folder - MAW (Deprecated)
'MenAtWork\MultiColumnWizard\Event\GetOptionsEvent' => 'system/modules/multicolumnwizard/src/MenAtWork/Event/GetOptionsEvent.php',
// Src Folder - MCW
'MultiColumnWizard\Event\GetOptionsEvent' => 'system/modules/multicolumnwizard/src/MultiColumnWizard/Event/GetOptionsEvent.php',
'MultiColumnWizard\DcGeneral\UpdateDataDefinition' => 'system/modules/multicolumnwizard/src/MultiColumnWizard/DcGeneral/UpdateDataDefinition.php',
));
23 changes: 23 additions & 0 deletions system/modules/multicolumnwizard/config/event_listeners.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* Contao Open Source CMS
*
* @copyright MEN AT WORK 2017
* @package MultiColumnWizard
* @license LGPL
* @filesource
*/

use ContaoCommunityAlliance\DcGeneral\Factory\Event\BuildDataDefinitionEvent;

This comment has been minimized.

Copy link
@bytehead

bytehead Oct 6, 2017

Contributor

You've introduced a dependency to DcGeneral here... (MCW > 3.3.10)

use MultiColumnWizard\DcGeneral\UpdateDataDefinition;

return array
(
BuildDataDefinitionEvent::NAME => array(
array(
array(new UpdateDataDefinition(), 'addMcwFields'),
UpdateDataDefinition::PRIORITY
)
)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* Contao Open Source CMS
*
* @author Christian Schiffler <[email protected]>
* @copyright CyberSpectrum 2014
* @package MultiColumnWizard
* @license LGPL-3+
* @filesource
*/

namespace MenAtWork\MultiColumnWizard\Event;

/**
* This event is fired when a MultiColumnWizard wants to retrieve the options for a sub widget in dc-general context.
*
* @deprecated Use the \MultiColumnWizard\Event\GetOptionsEvent class.
*/
class GetOptionsEvent extends \MultiColumnWizard\Event\GetOptionsEvent
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

/**
* Contao Open Source CMS
*
* @copyright MEN AT WORK 2017
* @package MultiColumnWizard
* @license LGPL
* @filesource
*/

namespace MultiColumnWizard\DcGeneral;

use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\DefaultProperty;
use ContaoCommunityAlliance\DcGeneral\Factory\Event\BuildDataDefinitionEvent;

/**
* Class UpdateDataDefinition
*
* @package MultiColumnWizard\DcGeneral
*/
class UpdateDataDefinition
{
const PRIORITY = -500000;

/**
* Add all fields from the MCW to the DCA. This is needed for some fields, because other components need this
* to create the widget/view etc.
*
* @param BuildDataDefinitionEvent $event
*
* @return void
*/
function addMcwFields(BuildDataDefinitionEvent $event)
{
// Get the container and all properties.
$container = $event->getContainer();
$properties = $container->getPropertiesDefinition();

/** @var DefaultProperty $property */
foreach ($properties as $property) {
// Only run for mcw.
if ('multiColumnWizard' !== $property->getWidgetType()) {
continue;
}

// Get the extra and make an own field from it.
$config = $property->getExtra();

// If we have no data here, go to the next.
if(empty($config['columnFields']) || !is_array($config['columnFields'])){
continue;
}

foreach ($config['columnFields'] as $fieldKey => $fieldConfig) {
// Build the default name.
$name = sprintf('%s__%s', $property->getName(), $fieldKey);

// Make a new field and fill it with the data from the config.
$subProperty = new DefaultProperty($name);
foreach ($fieldConfig as $key => $value) {
switch ($key) {
case 'label':
$subProperty->setLabel($value);
break;

case 'description':
if (!$subProperty->getDescription()) {
$subProperty->setDescription($value);
}
break;

case 'default':
if (!$subProperty->getDefaultValue()) {
$subProperty->setDefaultValue($value);
}
break;

case 'exclude':
$subProperty->setExcluded((bool)$value);
break;

case 'search':
$subProperty->setSearchable((bool)$value);
break;

case 'filter':
$subProperty->setFilterable((bool)$value);
break;

case 'inputType':
$subProperty->setWidgetType($value);
break;

case 'options':
$subProperty->setOptions($value);
break;

case 'explanation':
$subProperty->setExplanation($value);
break;

case 'eval':
$subProperty->setExtra(
array_merge(
(array) $subProperty->getExtra(),
(array) $value
)
);
break;

case 'reference':
$subProperty->setExtra(
array_merge(
(array) $subProperty->getExtra(),
array('reference' => &$value['reference'])
)
);
break;

default:
}
}

// Add all to the current list.
$properties->addProperty($subProperty);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Contao Open Source CMS
*
Expand All @@ -9,7 +10,7 @@
* @filesource
*/

namespace MenAtWork\MultiColumnWizard\Event;
namespace MultiColumnWizard\Event;

use ContaoCommunityAlliance\DcGeneral\Data\ModelInterface;
use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface;
Expand Down

0 comments on commit 747bdc7

Please sign in to comment.