Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Merge 23e4169 into c22d5a7
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe Court committed Mar 10, 2018
2 parents c22d5a7 + 23e4169 commit 8bf247a
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 6 deletions.
112 changes: 112 additions & 0 deletions Classes/DataCollectors/FormzCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Romm\Formz\DataCollectors;

use Konafets\TYPO3DebugBar\DataCollectors\BaseCollector;
use Romm\Formz\Form\FormObject;
use Romm\Formz\Form\FormObjectFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

class FormzCollector extends BaseCollector
{
/**
* @var FormObject[]
*/
private $formzInstances = [];

/**
* Called by the DebugBar when data needs to be collected
*
* @return array Collected data
*/
function collect()
{
$formzInstances = $this->getFormzInstances();

foreach ($formzInstances as $instance) {
$debug .= DebuggerUtility::var_dump($instance, $instance->getName(),10,false,true, true);
$forms[] = [
'name' => $instance->getName(),
'params' => [
'Class Name' => $instance->getClassName(),
'Fields' => $instance->getProperties(),
'Hash' => $instance->getHash()
]
];
}

$formsCount = \count($formzInstances);
$output = [
'formsCount' => $formsCount, // Number of formz instance in the page
'debug' => $debug,
'status' => '<b>' . $formsCount . '</b> Formz instance(s) in this page',
'forms' => $forms,
'console' => '' // div for output console javascript
];

return $output;
}

/**
* @return FormObject[]
*/
public function getFormzInstances()
{
$formObjFactory = GeneralUtility::makeInstance(FormObjectFactory::class);

foreach ($formObjFactory->getInstances() as $instance) {
$this->formzInstances[$instance->getName()] = $instance;
}

return $this->formzInstances;
}

/**
* Returns a hash where keys are control names and their values
* an array of options as defined in {@see DebugBar\JavascriptRenderer::addControl()}
*
* @return array
*/
function getWidgets()
{
$name = $this->getName();

return [
(string) $name => [
'icon' => $name,
'widget' => 'PhpDebugBar.Widgets.FormzWidget',
'map' => $name,
"default" => '[]',
],
"$name:badge" => [
'map' => 'formz.formsCount',
'default' => 0,
],
];
}

/**
* Returns the unique name of the collector
*
* @return string
*/
public function getName()
{
return 'formz';
}
}
8 changes: 8 additions & 0 deletions Classes/Form/FormObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,12 @@ public function injectTypoScriptService(TypoScriptService $typoScriptService)
{
$this->typoScriptService = $typoScriptService;
}

/**
* @return FormObject[]
*/
public function getInstances(): array
{
return $this->instances;
}
}
13 changes: 13 additions & 0 deletions Classes/ViewHelpers/FormViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Romm\Formz\AssetHandler\Connector\AssetHandlerConnectorManager;
use Romm\Formz\AssetHandler\Html\DataAttributesAssetHandler;
use Romm\Formz\Core\Core;
use Romm\Formz\DataCollectors\FormzCollector;
use Romm\Formz\Exceptions\ClassNotFoundException;
use Romm\Formz\Exceptions\EntryNotFoundException;
use Romm\Formz\Exceptions\InvalidOptionValueException;
Expand Down Expand Up @@ -115,6 +116,11 @@ class FormViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper
*/
protected $controllerService;

/**
* @var \Romm\Formz\DataCollectors\FormzCollector
*/
protected $formzCollector;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -521,4 +527,11 @@ public function injectControllerService(ControllerService $controllerService)
{
$this->controllerService = $controllerService;
}

/**
* @param FormzCollector $formzCollector
*/
public function injectFormzCollector(FormzCollector $formzCollector) {
$this->formzCollector = $formzCollector;
}
}
96 changes: 92 additions & 4 deletions Resources/Public/JavaScript/Formz.Debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,106 @@ Fz.Debug = (function () {

switch (type) {
case Fz.TYPE_WARNING:
color = 'color: yellow; font-weight:bold;';
color = 'color: orange;';
console.warn('%c[FormZ] ' + value + '%c', color, 'color: orange;');
break;
case Fz.TYPE_ERROR:
color = 'color: red; font-weight:bold;';
color = 'color: red;';
console.error('%c[FormZ] ' + value + '%c', color, 'color: red;');
break;
case Fz.TYPE_NOTICE:
color = 'color: blue;';
console.info('%c[FormZ] ' + value + '%c', color, 'color: blue;');
break;
default:
color = 'color: blue; font-weight:bold;';
color = 'color: black;';
console.log('%c[FormZ] ' + value + '%c', color, 'color: black;');
break;
}

console.log('%c[FormZ - ' + type + '] %c' + value, color, 'color: black;');
var consoleTypo3Debugbar = document.querySelector('.phpdebugbar-widgets-console');
if (consoleTypo3Debugbar) {
consoleTypo3Debugbar.innerHTML = value;
consoleTypo3Debugbar.style = color;
}

}
}
};
})();

if (typeof(PhpDebugBar) === 'undefined') {
// namespace
var PhpDebugBar = {};
PhpDebugBar.$ = jQuery;
}

(function($) {

var csscls = PhpDebugBar.utils.makecsscls('phpdebugbar-widgets-');

/**
* Widget for the displaying FormZ informations
*
* Options:
* - data
*/
var FormzWidget = PhpDebugBar.Widgets.FormzWidget = PhpDebugBar.Widget.extend({

className: csscls('formz'),

render: function() {

this.$status = $('<div />').addClass(csscls('status')).appendTo(this.$el);
this.$debug = $('<div />').addClass(csscls('debug')).appendTo(this.$el);
this.$list = new PhpDebugBar.Widgets.ListWidget(
{
itemRenderer: function(li, form) {
if (form.name) {
$('<h3><span title="Name" /></h3>').addClass(csscls('name')).text(form.name).appendTo(li);
}

if (form.className) {
$('<span title="ClassName" />').addClass(csscls('className')).text(form.className).appendTo(li);
}
if (form.params && !$.isEmptyObject(form.params)) {
var table = $('<table style="display: none;"><tr><th colspan="2">Configuration</th></tr></table>').addClass(csscls('params')).appendTo(li);
for (var key in form.params) {
if (typeof form.params[key] !== 'function') {
table.append('<tr><td class="' + csscls('name') + '">' + key + '</td><td class="' + csscls('value') +
'">' + form.params[key] + '</td></tr>');
}
}
li.css('cursor', 'pointer').click(function() {
if (table.is(':visible')) {
table.hide();
} else {
table.show();
}
});
}
}
}
);
this.$list.$el.appendTo(this.$el);
this.$console = $('<div />').addClass(csscls('console')).appendTo(this.$el);

this.bindAttr('data', function(data) {

if (data.length <= 0) {
return false;
}

this.$list.set('data', data.forms);
this.$status.empty();
this.$console.empty();

this.$status.append(data.status);
this.$debug.append(data.debug);
this.$console.append(data.console);
this.$el.append(data);
});
}
});
})(PhpDebugBar.$);

3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"satooshi/php-coveralls": "^1.0",
"nimut/testing-framework": "^1.0"
},
"suggest": {
"konafets/typo3_debugbar": "debug formz more easyly"
},
"autoload": {
"psr-4": {
"Romm\\Formz\\": "Classes/"
Expand Down
10 changes: 8 additions & 2 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function ($extensionKey) {
// Registering the cache.
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][\Romm\Formz\Service\CacheService::CACHE_IDENTIFIER])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][\Romm\Formz\Service\CacheService::CACHE_IDENTIFIER] = [
'backend' => \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class,
'backend' => \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class,
'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
'groups' => ['all', 'system', 'pages']
'groups' => ['all', 'system', 'pages']
];
}

Expand All @@ -35,6 +35,12 @@ function ($extensionKey) {
$container = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
$typo3Version = \TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version();

if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('typo3_debugbar') && version_compare($typo3Version, '8.7.0', '>=')) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\Konafets\TYPO3DebugBar\Typo3DebugBar::class] = ['className' => \Romm\Formz\Overrides\Typo3DebugBar::class];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\Konafets\TYPO3DebugBar\Typo3DebugBarServiceProvider::class] = ['className' => \Romm\Formz\Overrides\Typo3DebugBarServiceProvider::class];
}


if (version_compare($typo3Version, '8.3.0', '<')) {
$container->registerImplementation(\Romm\Formz\ViewHelpers\FormViewHelper::class, \Romm\Formz\Service\ViewHelper\Legacy\OldFormViewHelper::class);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\Romm\Formz\ViewHelpers\FormViewHelper::class] = [
Expand Down

0 comments on commit 8bf247a

Please sign in to comment.