Which files are needed for an own finisher to work in the Typo3 form extension? - typo3

I want to make my own finisher but I don't have a clue what is needed.
I have
\Domain\Finishers\MyOwnFinisher.php // with the finisher class
Configuration\Form\Backend.yaml //which should tell my TYPO3 where to look for the finisher
Configuration\TypoScript\setup.typoscript //telling EXT:form where the Backend.yaml is
but still I get an exception:
"The finisher preset identified by “xxx” could not be found, or the implementationClassName was not specified."
Is there some file I forgot? Some configuration I must set?
Backend.yaml
prototypes:
standard:
finishersDefinition:
MyOwn:
implementationClassName: 'mastar\testprivateext\Classes\Domain\Finishers\MyOwnFinisher'
options:
table: tx_testprivateext_domain_model_YetAnotherTable
setup.typoscript
#import "EXT:testprivateext/Configuration/TypoScript/Setup/*.typoscript"
plugin.tx_form.settings.yamlConfigurations {
901 = EXT:testprivateext/Configuration/Form/Backend.yaml
}
MyOwnFinisher.php
<?php
declare(strict_types=1);
namespace mastar\testprivateext\Classes\Domain\Finishers;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException;
use TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
class MyOwnFinisher extends AbstractFinisher {
protected $defaultOptions = [
'table' => 'tx_testprivateext_domain_model_YetAnotherTable',
'pid' => '34',
'name' => '',
'unterzeile' => '',
'strasse' => '',
'hausnummer' => '',
'plz' => '',
'ort' => '',
'telefon' => '',
'fax' => '',
'web' => '',
];
protected $shortFinisherIdentifier = 'MyOwn';
protected $databaseConnection;
protected function executeInternal() {
/// Stuff get's done here
}
}
Thanks in advance!

You have some definition in the yaml file, I complete it as I never know if you missed it or left it out:
TYPO3:
CMS:
Form:
prototypes:
standard:
finishersDefinition:
MyOwn:
implementationClassName: 'mastar\testprivateext\Classes\Domain\Finishers\MyOwnFinisher'
options:
table: tx_testprivateext_domain_model_YetAnotherTable
Beside that I never see an obvious fault and guess that you know the documentation how to write an own finisher.
One issue when new classes are added can sometimes be solved by clearing the cache and dumping autoload.
Furthermore it might be helpful to check the logfile, not all problems are reported by the log inside the TYPO3 backend.
EDIT:
I just see this is wrong:
implementationClassName:
'mastar\testprivateext\Classes\Domain\Finishers\MyOwnFinisher'
and should be instead:
implementationClassName:
'mastar\testprivateext\Domain\Finishers\MyOwnFinisher'
So actually you've to separate paths and namespace, they are similar but not the same. Important might be the vendor and extensionName in the namespace too, I'd advise to read the extbase tutorial if you never understand namespaces well.

Related

TYPO3 system extension "install" overwrite with my own class

I would like to override a method of TYPO3 system extension "instal" -> Class TYPO3\CMS\Install\SystemEnvironment\Check with my own class VENDOR\Examples\Xclass\Backend\Check but it's not working.
Other classes in the system extesion for example as TYPO3\CMS\Backend\Controller\LoginController or TYPO3\CMS\Backend\Template\DocumentTemplate can I without problems with the help of XLASS overwrite.
It is generally possible to overwrite the install tools classes from own extension?
<?php
defined('TYPO3_MODE') || die('Access denied.');
if (TYPO3_MODE === 'BE') {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Install\\SystemEnvironment\\Check'] = array(
'className' => 'ALEX\\Examples\\Xclass\\Backend\\Check'
);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Backend\\Controller\\LoginController'] = array(
'className' => 'ALEX\\Examples\\Xclass\\Backend\\LoginController'
);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Backend\\Template\\DocumentTemplate'] = array(
'className' => 'ALEX\\Examples\\Xclass\\Backend\\DocumentTemplate'
);
}
This is not possible as the class is not called via GeneralUtility::makeInstance. Furthermore it is also stated in the class:
#internal This class is only meant to be used within EXT:install and
is not part of the TYPO3 Core API.
If you are missing a feature or think you got a bug you should open an issue at https://forge.typo3.org/projects/typo3cms-core/issues

How to add custom wizards in typo3 7 TCA?

When I try to add the wizard named wizard_geo_selector in TCA ,there arised an error "module not registered".Please tell me how to register the wizard properly in the TCA.?
In TYPO3 Version 7.6 new wizards are added like this:
Inside your extension create the directory Configuration/Backend/
In the new directory create a file Routes.php, it will be found automatically, no mentioning in ext_localconf.php or ext_tables.php is required. If you still need Ajax you can add the file AjaxRoutes.php in the same folder.
Content for Routes.php:
return array(
'my_wizard_element' => array(
'path' => '/wizard/tx_geoselecotor/geo_selector_wizard',
'target' => \Path\To\your\class\WizardGeoSelector::class . '::WizardAction'
),
);
Content for AjaxRoutes.php
<?php
/**
* Definitions for routes provided by EXT:backend
* Contains all AJAX-based routes for entry points
*
* Currently the "access" property is only used so no token creation + validation is made
* but will be extended further.
*/
return array('my_ajax_element' => array(
'path' => 'tx_geoselecotor/my_ajax_route',
'target' => \Path\To\your\class\MyAjaxController::class .'::myAjaxFunction'
));
If you're unsure about the notation you can compare with existing entries in the Global Variables in the Backend:
Navigate to System -> Configuration -> Backend Routes
The route of the paths is handled different, for Ajax it's always "ajax" prepended, so you've never to add it to the path, else it's twice in the route. For the common route there is no change concerning the defined string.
Now the wizard can be used and even it never has to be defined in ext_tables.php it has to be mentioned there from any table-field in the configuration-area (module[name]):
'table_field_for_wizard' => array(
'label' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xml:table_name.tx_myextension_wizard',
'config' => array (
'type' => 'user',
'userFunc' => 'Path/to/class/without/wizard->renderForm',
'wizards' => array(
'my_wizard' => array(
'type' => 'popup',
'title' => 'MyTitle',
'JSopenParams' => 'height=700,width=780,status=0,menubar=0,scrollbars=1',
'icon' => 'EXT:' . $_EXTKEY . '/Resources/Public/img/link_popup.gif',
'module' => array(
'name' => 'my_wizard_element',
'urlParameters' => array(
'mode' => 'wizard',
'ajax' => '0',
'any' => '... parameters you need'
),
),
),
'_VALIGN' => 'middle',
'_PADDING' => '4',
),
# Optional
#'softref'=>'something',
),
),
In the userFunc Path/to/class/without/wizard->renderForm you've to create a button which is linking to the wizard and onClick the wizard will open with the route you defined in Routes.php and the optional urlParameters.
Currently I never found this whole item explained in the core-documentation.
Edit:
Details about routing can be found here: Routing
The rendering process can be found here: Rendering / NodeFactory
You should probably read also the outer context of the linked paragraph.
Edit 2:
An example extension can be found here, some things never work 100% but the wizard is working. The extension is for TYPO3 Version 7:
https://github.com/DavidBruchmann/imagemap_wizard
Ricky's answer doesn't really work anymore, since addModulePath ist deprecated since version 7.
Also, just registering the module like this still give's you said error.
The only thing that keeps the wizard going again is this:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule('wizard','pbsurvey_answers',"",\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY).'wizard/');
But when you add this, the module appears as a new point in your TYPO3 backend.
IN TCA add the wizard like follows:
'module' => array(
'name' => 'wizard_geo_selector',
),
In ext_tables.php register the wizard.
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModulePath(
'wizard_geo_selector',
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Modules/Wizards/Yourwizardname/'
);
Keep in mind this is deprecated since Typo3 7 and removed in Typo3 8.So you can use this method upto Typo3 7.For Typo3 8 do use the method specified by David below.

Symfony2 autocomplete form bundle

I use this bundle: GenemuFormBundle
I install it due to all information on this site.
But it still dont work.
Here is my type form:
$builder
->add('PermitsCompany', 'genemu_jqueryautocompleter_entity', array(
'route_name' => 'ajax_company',
'class' => 'MainCoreBundle:Company',
'property'=>'name'
))
;
Here is my routing:
ajax_company:
defaults: { _controller: MainAdminBundle:Permits:ajaxCompany}
pattern: /ajax_company/
type: annotation
And here is my controller:
/**
* #Route("/ajax_company", name="ajax_company")
*/
public function ajaxCompanyAction(Request $request)
{
$permits = $this->getDoctrine()->getRepository('MainCoreBundle:Company')->findAll();
$json = array();
foreach ($permits as $permit) {
$json[] = array(
'label' => $permit->getName(),
'value' => $permit->getId()
);
}
$response = new Response(json_encode($json));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
I have no idea what I am doing wrong. I have no error. But autocomplete did not work.
When i go to route /ajax_company/ i can see values from data base like here:
[{"property":"Company 1","value":1},{"property":"Company 2","value":2},{"Company":"Company 3","value":3},{"property":"Company 4","value":4}]
Did I add forget something in twig? I have only form_widget
Try including form_javascript or form_stylesheet, in your twig template.
From https://github.com/genemu/GenemuFormBundle#template:
Template
You use GenemuFormBundle and you seen that it does not work! Maybe you
have forgotten form_javascript or form_stylesheet.
The principle is to separate the javascript, stylesheet and html. This
allows better integration of web pages.

Class Sofzo_From not found error when implementing Sozfo TinyMCE solution

I'm trying to implement TinyMCE to text areas using the solution mentioned in Sofzo. But when I try to extend the Sofzo_Form I get the following error :
Fatal error: Class 'Sozfo_Form' not found in /home/foldername/public_html/application/forms/PageForm.php on line 4
What I have done so far -
Uploaded the Sofzo files to library with following directory structure
/library
../Sozfo
../Form.php
../../Form
../../../Element
../../../../TinyMce.php
../../View
../../../Helper
../../../Exception.php
../../../../FormTinyMce.php
../../../../TinyMce.php
Loaded the classes in application.ini as
Autoloadnamaspaces[] = "Sofzo_"
And in bootstrap as
$autoLoader = Zend_Loader_Autoloader::getInstance();
$autoLoader->registerNamespace('Zend_');
$autoLoader->registerNamespace('SF_');
$autoLoader->registerNamespace('CMS_');
$autoLoader->registerNamespace('Sofzo_');
$loader = new Zend_Loader_PluginLoader();
$loader->addPrefixPath('Zend_View_Helper', 'Zend/View/Helper/')
->addPrefixPath('Storefront_View_Helper',
'application/modules/storefront/views/helpers')
->addPrefixPath('Sozfo_Form', 'Sozfo/');
$view=new Zend_View();
$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');
But when I try to extent the Sofzo_Form in Page_Form as
class Form_PageForm extends Sozfo_Form { }
This issue was solved thanks to Tim Fountain. But now when I load an element as
$this->addElement('tinyMce', 'message', array(
'label' => 'Message',
'required' => true,
'cols' => '50',
'rows' => '10',
'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini', 'moderator')
));
I get the following error
Plugin by name 'FormTinyMce' was not found in the registry
Read through several comments in original site and they are said to add
$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');
to bootstrap. I've already done that, but I'm guessing I'm not doing something right. Help is much appreciated.
I think the issue is ZF can't find the class because it doesn't know about the Sozfo_ namespace. You've attempted to register this namespace in two different ways, but both of them are incorrect.
In application.ini, you have:
Autoloadnamaspaces[] = "Sofzo_"
But this should be:
autoloaderNamespaces[] = "Sozfo_"
Then in the bootstrap you've tried to register it with:
$autoLoader->registerNamespace('Sofzo_');
but presumably this should be:
$autoLoader->registerNamespace('Sozfo_');
(note spelling). Which ever fix you apply you should only use one of these methods, as they do the same thing.
If it still doesn't work after that then there's an issue with your include_path.
Edit: To fix the view helper path, try this instead of the two lines you currently have:
$view = new Zend_View();
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
$stack = Zend_Controller_Action_HelperBroker::getStack();
$stack->push($viewRenderer);
$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');
This adds the helper path to a view object like you have but also supplies it to the view renderer (which is what renders all the view scripts). If you don't do this then the view renderer uses its own view object, so the view object you setup in the bootstrap is never used for anything.
If this doesn't work, try passing a full path as the first parameter to addHelperPath instead:
$view->addHelperPath(APPLICATION_PATH.'/../library/Sozfo/View/Helper', 'Sozfo_View_Helper');

Customize errors symfony

There are some "best practice" in Symfony to customize form errors?
For exemple, if i would to show "Campo obligatorio" when the field is required.
1)How can i do that better way and independent from what forms call it?
2)How can i customize message 'An object with the same "%namefield" already exist.' ?
Thanks
updated
sorry, but if i try to do 'invalid' how you said me... it print me the same error
$this->setValidator('urlres', new sfValidatorString(array(
'min_length' => 6,
), array(
'min_length' => 'URL must be longer',
'required' => 'Required field',
'invalid' => 'URL exist'
)));
prints me:
* An object with the same "urlres" already exist.
updated
Felix, your solution is fantastic but it prints me this error:
"urlres: that url already exists"
Are there some way to delete "field:" ??
Thanks
Maybe this form post helps you:
Put the code
sfValidatorBase::setDefaultMessage('required', 'Field required');
in the "configure" of you application configuration apps/youApp/config/yourAppConfiguration.class.php.
You should be able to set the default value for every error message type this way.
If you want to set certain error messages for certain fields, think about to create a form class that defines all this and let all other forms inherit from this one.
The subclasses then only specify which fields should be displayed (and maybe custom validation logic).
You can find an example how to do this in the Admin Generator chapter of the symfony book.
This is the cleanest approach IMHO.
Edit:
If you want leave fields blank, you have to add the required => false option:
'email' => new sfValidatorEmail(array('required' => false))
Regarding the error message: This sounds like the urlres is marked as unique in the database table and the value already exists. Maybe you should check the database schema definition.
Edit 2:
To test both, length and uniqueness, you should use sfValidatorAnd and sfValidatorDoctrineUnique:
$this->setValidator('urlres', new sfValidatorAnd(
array(
new sfValidatorString(
array( 'min_length' => 6, ),
array( 'required' => 'Required field',
'min_length' => 'URL must be at least %min_length% chars long.' )
),
new sfValidatorDoctrineUnique(
array( 'model' => 'yourModel',
'column' => 'theColumn',
'primary_key' => 'thePrimaryKeyColumn',
'throw_global_error' => false),
array('invalid' => "That URL already exists")
)
));
Also your use of the invalid error code in the string validator is not correct. You set the invalid message to
URL exists but how can a string validator know this? It only checks whether the given string meets the min_length, max_length criteria or not.
Btw I assumed that you use Doctrine but I think the same validators are available for Propel.
Edit 3:
Set the option 'throw_global_error' => false. But I am not sure if that works.
You can also have a look at the source code if it helps you.
Let me try to help you.
You can easily customize standard form errors in configure method of your form class. Here is an example:
1)
<?php
class myForm extends BaseMyForm
public function configure(){
parent::configure();
$this->setValidator(
'my_field' => new sfValidatorString(
array('min_length'=>3, 'max_length'=>32, 'required'=>true),
array('required' => 'Hey, this field is required!')
)
);
}
2) Just change a message that has a code 'invalid'.
All you need is just find a valid message code to customize particular default messages. More info - Symfony Forms in Action: Chapter 2 - Form Validation
Updated:
And if you don't want to customize error messages in all your form classes, just create your own base validator class:
abstract class myBaseValidator extends sfValidatorBase
and there redefine default 'required' and 'invalid' messages.
Are there some way to delete "field:"
??
Yes: throw_global_error => true