[TYPO3-mvc] Using extbase plugin as configuration for another extbase plugin ?

Adrien Crivelli adrien.crivelli at gmail.com
Fri Mar 23 01:26:36 CET 2012


Hi,

I ended up using something much more hackish than what you seem to suggest.
But at least it's working :)

So I declare a FlexForm in ext_tables.php:

$extensionName = t3lib_div::underscoredToUpperCamelCase($_EXTKEY);
> $pluginSignature = strtolower($extensionName) . '_myplugin';
> $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist'][$pluginSignature]
> = 'layout,recursive,select_key,pages';
> $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature]
> = 'pi_flexform';
> Tx_Flux_Core::registerFluidFlexFormPlugin(
> $_EXTKEY,
> $pluginSignature,
> 'EXT:' . $_EXTKEY . '/Configuration/FlexForms/flexform_myplugin.xml',
> array('defaultValue1' => 'someDefaultValue'),
> 'Configuration' // because the configuration is located in section
> Configuration
> );




The flexform file, flexform_myplugin.xml, is actually very simple and looks
like that:

{namespace flux=Tx_Flux_ViewHelpers}
> <f:layout name="DynamicFlexForm.xml" />
> <f:section name="Configuration">
> <flux:flexform id="my-flexform">
> <flux:flexform.field.userFunc name="settings.toolbar" label=""
> userFunc="Tx_Speciality_Configuration_FlexForms_ToolbarRenderer->renderMyToolbar"
> />
> </flux:flexform>
> </f:section>




The userFunc call the ToolbarRenderer class and there goes all the
magick...uhm hacks...:

class Tx_Speciality_Configuration_FlexForms_ToolbarRenderer
> {
> /**
>  * Renders the toolbar action for given plugin and controller
>  * @param string $pluginName
>  * @param string $controllerName
>  * @param array $PA
>  * @return string HTML
>  */
> protected function renderToolbar($pluginName, $controllerName, $PA)
> {
> $extensionName = 'Speciality';
> $pluginNamespace =
> Tx_Extbase_Utility_Extension::getPluginNamespace($extensionName,
> $pluginName);
>
> // Inject toolbar values from database into GET parameter so they will be
> seen as default values when generating toolbar's HTML
> if (is_array($PA['itemFormElValue']))
> {
> $_GET[$pluginNamespace]['toolbar'] = $PA['itemFormElValue'];
> }
>
> // Defines the current action to be "toolbar" (needed when editing via
> feeditadvanced, otherwise it would use default action 'index' from Frontend)
> $_GET[$pluginNamespace]['action']= 'toolbar';
>
> // Add default controller and actions so extbase knows what to do
> $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$pluginName]['controllers'][$controllerName]['actions']
> = array('toolbar');
>
> // Read storage PIDs from configuration files because we don't know how to
> get them otherwise
> $constants = file_get_contents(t3lib_extMgm::extPath('speciality') .
> '/Configuration/TypoScript/constants.txt');
> preg_match('/storagePid\\s*=\\s*([^\\s]+)/', $constants, $m);
> $storagePid = $m[1];
>
> $configuration = array(
> 'extensionName' => $extensionName,
> 'pluginName' => $pluginName,
> 'persistence' => array(
> 'storagePid' => $storagePid,
> )
> );
> // Run extbase with defined configuration
> $objectManager =
> t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
> $extbaseBootstrap = $objectManager->get('Tx_Extbase_Core_Bootstrap');
> $content = $extbaseBootstrap->run($content, $configuration);
> // Rename form fields so their are automatically saved by TCE
> $content = str_replace('name="' . $pluginNamespace . '[toolbar]', 'name="'
> . $PA['itemFormElName'], $content);
>
> return $content;
> }
>
> /**
>  * Returns the rendered toolbar for MyController
>  * @param array $PA
>  * @return string HTML
>  */
> public function renderMyToolbar($PA)
> {
> return $this->renderToolbar('MyPlugin', 'MyController', $PA);
> }

}


That's about it. You get an Extbase action rendered as configuration for an
extbase plugin in backend. I still had to add an few extra things such as
prevent JavaScript conflicts (jQuery vs Prototype), and
XCLASS t3lib_TCEmain to be able to "uncheck" groups of checkboxes
(basically always overwrite previous values in database, never merge with
them).

I guess it could be made into something less hardcoded and more generic. If
anybody is interested I'll be happy to give more details...

Cheers,

Adrien


More information about the TYPO3-project-typo3v4mvc mailing list