Skip to content

Commit

Permalink
Merge tag '2.1.8' into master
Browse files Browse the repository at this point in the history
This is a bigfix release.

This release has:
- Use the max results per page for limit options, if the options all is selected #361
- No use the `tl_limit` as value for reset the limit of the models in the list #505
- Fixed callbacks handle http exceptions as plain exceptions #524
- Hotix colorpicker see Issue #544
- Hotfix getFilterOptions cut the table name
- Do not add saveNcreate if "nc" parameter given.
- Do not add saveNclose if "nb" parameter given
- Is hidden input field, by the widget instead of the property
- update readme
- Fix if the label of the widget is empty, so not generate the help text for the widget #531
- Add the listener if the mcw is installed #527
- Do not set background color of search input field if empty string #506
- Fix default data provider get filter options #539
- If input provider call has parameter mark keep unused #510
- Not manipulate the toggle command from the legacy callback listener #521
- Filter the model property fields provided by the data provider when they are stored in the database
  • Loading branch information
baumannsven committed Aug 27, 2020
2 parents ba6b920 + 38d150e commit 89a5ef8
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 38 deletions.
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,30 @@
[![Latest Version on Packagist](http://img.shields.io/packagist/v/contao-community-alliance/dc-general.svg)](https://packagist.org/packages/contao-community-alliance/dc-general)
[![Installations via composer per month](http://img.shields.io/packagist/dm/contao-community-alliance/dc-general.svg)](https://packagist.org/packages/contao-community-alliance/dc-general)


DC_General
==========

Universal data container for Contao.
The DC_General is a universal data container for Contao and is an alternative
for the DC_Table of the Contao framework.

With the DC_General we facilitate programming with excellent functions and
influence possibilities.


Different to Contao DC_Table
============================

With the use of the DC_General there are many advantages, e.g.

* Object-oriented data container definitions
* Event driven
* abstraction of the data source
* modular design
* verification of data - no invalid records
* improved configuration of dependencies between data containers
* more control through events

We hope that ultimatively this driver will become the de facto standard
driver for Contao extensions in the future, once proven to be stable enough.

How to use
==========
Expand All @@ -26,3 +43,15 @@ There are some notable changes in compatibility considering DC_Table:
3. The system is totally event driven and relevant information (like the model
in scope) is attached to the events.


Help for the start
==================

You can start with our new [documentation](https://dc-general.readthedocs.io/de/latest/index.html)
(currently in german) or [older one](http://contao-community-alliance.github.io/dc-general-docs/) (in english).

We have an overview of [DCA mapping](https://dc-general.readthedocs.io/de/latest/reference/dca_mapping.html)
and [Callbacks](https://dc-general.readthedocs.io/de/latest/reference/callbacks.html).

In our [examples](https://github.com/contao-community-alliance/dc-general-example)
you can see the difference to DC_Table.
4 changes: 4 additions & 0 deletions src/Contao/Callback/Callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace ContaoCommunityAlliance\DcGeneral\Contao\Callback;

use Contao\CoreBundle\Exception\ResponseException;
use Contao\System;
use ContaoCommunityAlliance\DcGeneral\Exception\DcGeneralRuntimeException;
use Symfony\Component\DependencyInjection\Container;
Expand Down Expand Up @@ -63,6 +64,7 @@ public static function call($callback, $_ = null)
*
* @return mixed
*
* @throws ResponseException Throw the response exception.
* @throws DcGeneralRuntimeException When the callback throws an exception.
*/
public static function callArgs($callback, array $args = [])
Expand All @@ -71,6 +73,8 @@ public static function callArgs($callback, array $args = [])
$callback = static::evaluateCallback($callback);

return \call_user_func_array($callback, $args);
} catch (ResponseException $e) {
throw $e;
} catch (\Exception $e) {
$message = $e->getMessage();
}
Expand Down
10 changes: 7 additions & 3 deletions src/Contao/Callback/ModelOperationButtonCallbackListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2019 Contao Community Alliance.
* (c) 2013-2020 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -15,7 +15,7 @@
* @author Tristan Lins <tristan.lins@bit3.de>
* @author David Molineus <mail@netzmacht.de>
* @author Sven Baumann <baumann.sv@gmail.com>
* @copyright 2013-2019 Contao Community Alliance.
* @copyright 2013-2020 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand All @@ -24,6 +24,7 @@

use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetOperationButtonEvent;
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\View\CommandInterface;
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\View\ToggleCommandInterface;

/**
* Class ModelOperationButtonCallbackListener.
Expand Down Expand Up @@ -62,6 +63,10 @@ public function setRestrictions($dataContainerName = null, $operationName = null
*/
public function wantToExecute($event)
{
if ($event->getCommand() instanceof ToggleCommandInterface) {
return false;
}

return parent::wantToExecute($event)
&& (empty($this->operationName)
|| ($this->operationName === $event->getKey())
Expand Down Expand Up @@ -109,7 +114,6 @@ public function update($event, $value)
return;
}

$event->setHtml($value);
$event->stopPropagation();
}

Expand Down
6 changes: 3 additions & 3 deletions src/Contao/InputProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2019 Contao Community Alliance.
* (c) 2013-2020 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -15,7 +15,7 @@
* @author Tristan Lins <tristan.lins@bit3.de>
* @author Stefan Heimes <stefan_heimes@hotmail.com>
* @author Sven Baumann <baumann.sv@gmail.com>
* @copyright 2013-2019 Contao Community Alliance.
* @copyright 2013-2020 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand Down Expand Up @@ -68,7 +68,7 @@ public function unsetParameter($key)
*/
public function hasParameter($key)
{
return (null !== Input::get($key));
return (null !== Input::get($key, false, true));
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/Contao/View/Contao2BackendView/ContaoWidgetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ protected function generateHelpText($property)
$label = $propInfo->getDescription();
$widgetType = $propInfo->getWidgetType();

if (null === $label
if (empty($label)
|| ('password' === $widgetType)
|| !\is_string($label)
|| !$GLOBALS['TL_CONFIG']['showHelp']
Expand Down Expand Up @@ -361,9 +361,8 @@ public function renderWidget($property, $ignoreErrors = false, PropertyValueBag
$this->widgetAddError($property, $widget, $inputValues, $ignoreErrors);

$propInfo = $this->getEnvironment()->getDataDefinition()->getPropertiesDefinition()->getProperty($property);
$extra = (array) $propInfo->getExtra();

$isHideInput = (isset($extra['isHideInput']) ?? $extra['isHideInput']);
$isHideInput = (bool) $widget->hideInput;

$hiddenFields = ($isHideInput) ? $this->buildHiddenFields($widget->value, $widget->name) : null;

Expand Down
29 changes: 16 additions & 13 deletions src/Contao/View/Contao2BackendView/EditMask.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,24 @@ protected function getEditButtons()
);
$buttons['save'] = $buttonTemplate->parse();

$buttonTemplate->setData(
[
'label' => $this->getButtonLabel('saveNclose'),
'attributes' => [
'type' => 'submit',
'name' => 'saveNclose',
'id' => 'saveNclose',
'class' => 'tl_submit',
'accesskey' => 'c'
if (!$this->getEnvironment()->getInputProvider()->getParameter('nb')) {
$buttonTemplate->setData(
[
'label' => $this->getButtonLabel('saveNclose'),
'attributes' => [
'type' => 'submit',
'name' => 'saveNclose',
'id' => 'saveNclose',
'class' => 'tl_submit',
'accesskey' => 'c'
]
]
]
);
$buttons['saveNclose'] = $buttonTemplate->parse();
);
$buttons['saveNclose'] = $buttonTemplate->parse();
}

if (!$this->isPopup() && $basicDefinition->isCreatable()) {
if ($basicDefinition->isCreatable()
&& !$this->getEnvironment()->getInputProvider()->getParameter('nc')) {
$buttonTemplate->setData(
[
'label' => $this->getButtonLabel('saveNcreate'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ public function __construct(RequestScopeDeterminator $scopeDeterminator)
*/
public static function getSubscribedEvents()
{
return [
$listeners = [
DcGeneralEvents::ACTION => [
['prepareGlobalAllButton', 9999],
['deactivateGlobalButton', 9999]
],
GetOptionsEvent::NAME => ['handleOriginalOptions', 9999],
BuildWidgetEvent::NAME => ['handleOriginalWidget', 9999]
];

if (\class_exists(GetOptionsEvent::class)) {
$listeners[GetOptionsEvent::NAME] = ['handleOriginalOptions', 9999];
}

return $listeners;
}

/**
Expand Down
18 changes: 11 additions & 7 deletions src/Data/DefaultDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2019 Contao Community Alliance.
* (c) 2013-2020 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -23,7 +23,7 @@
* @author Sven Baumann <baumann.sv@gmail.com>
* @author Ingolf Steinhardt <info@e-spin.de>
* @author Richard Henkenjohann <richardhenkenjohann@googlemail.com>
* @copyright 2013-2019 Contao Community Alliance.
* @copyright 2013-2020 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand Down Expand Up @@ -405,11 +405,10 @@ public function getFilterOptions(ConfigInterface $config)
{
$internalConfig = $this->prefixDataProviderProperties($config);
$properties = $internalConfig->getFields();
$property = $properties[0];

if (1 !== \count($properties)) {
throw new DcGeneralRuntimeException('objConfig must contain exactly one property to be retrieved.');
}
$property = $properties[0];

$queryBuilder = $this->connection->createQueryBuilder();
$queryBuilder->select('DISTINCT(' . $property . ')');
Expand All @@ -420,9 +419,14 @@ public function getFilterOptions(ConfigInterface $config)

$values = $statement->fetchAll(\PDO::FETCH_OBJ);

$filterPropertyName = $property;
// Remove the data provider name from the filter property name, if exist.
if (0 === \strpos($filterPropertyName, $this->source . '.')) {
$filterPropertyName = \substr($filterPropertyName, \strlen($this->source . '.'));
}
$collection = new DefaultFilterOptionCollection();
foreach ($values as $value) {
$collection->add($value->$property, $value->$property);
$collection->add($value->$filterPropertyName, $value->$filterPropertyName);
}

return $collection;
Expand Down Expand Up @@ -588,11 +592,11 @@ private function fieldPrefixer(array &$fields)
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
private function convertModelToDataPropertyArray(ModelInterface $model, $timestamp = 0)
private function convertModelToDataPropertyArray(ModelInterface $model, int $timestamp)
{
$data = [];
foreach ($model as $key => $value) {
if ($key === $this->idProperty) {
if (($key === $this->idProperty) || !$this->fieldExists($key)) {
continue;
}

Expand Down
24 changes: 21 additions & 3 deletions src/Panel/DefaultLimitElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ protected function getItemsPerPage()
return Config::get('resultsPerPage');
}

/**
* Retrieve the amount of max items to display per page.
*
* @return int
*/
protected function getMaxItemsPerPage()
{
return Config::get('maxResultsPerPage');
}

/**
* Calculate the total amount of items.
*
Expand Down Expand Up @@ -199,14 +209,22 @@ public function render(ViewTemplateInterface $viewTemplate)
{
$options = [
[
'value' => 'tl_limit',
'value' => '0,' . $this->getItemsPerPage(),
'attributes' => '',
'content' => $GLOBALS['TL_LANG']['MSC']['filterRecords']
]
];

$optionsPerPage = $this->getItemsPerPage();
$optionsTotal = \ceil($this->intTotal / $optionsPerPage);
switch ($this->getInputProvider()->getValue('tl_limit')) {
case 'all':
$optionsPerPage = ($this->intTotal >= $this->getMaxItemsPerPage())
? $this->getMaxItemsPerPage() : $this->getItemsPerPage();
break;

default:
$optionsPerPage = $this->getItemsPerPage();
}
$optionsTotal = \ceil($this->intTotal / $optionsPerPage);

for ($i = 0; $i < $optionsTotal; $i++) {
$first = ($i * $optionsPerPage);
Expand Down
2 changes: 1 addition & 1 deletion src/Panel/DefaultSearchElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function render(ViewTemplateInterface $viewTemplate)
];
}

$viewTemplate->set('class', 'tl_select' . ((null !== $this->getValue()) ? ' active' : ''));
$viewTemplate->set('class', 'tl_select' . (!empty($this->getValue()) ? ' active' : ''));
$viewTemplate->set('options', $options);
$viewTemplate->set('value', $this->getValue());

Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/contao/widget_backend_listeners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ services:
- name: kernel.event_listener
event: dc-general.view.contao2backend.build-widget
method: handleEvent
priority: -256

0 comments on commit 89a5ef8

Please sign in to comment.