Skip to content

Instantly share code, notes, and snippets.

@dacostafilipe
Created August 30, 2018 15:04
Show Gist options
  • Save dacostafilipe/4cf0409f0dbad4b0bf81918207bc7f04 to your computer and use it in GitHub Desktop.
Save dacostafilipe/4cf0409f0dbad4b0bf81918207bc7f04 to your computer and use it in GitHub Desktop.
Add "richtextConfiguration" to flux < 9
  1. Extend \FluidTYPO3\Flux\Form\Field\Text
	class Text extends \FluidTYPO3\Flux\Form\Field\Text
	{
		
		/**
		 * @var string
		 */
		protected $richtextConfiguration;
		
		public function buildConfiguration()
		{
			$configuration = parent::buildConfiguration();
			
			if(true === $this->getEnableRichText()) {
				$configuration['richtextConfiguration'] = $this->getRichtextConfiguration();
				$configuration['defaultExtras'] = '';
			}
			
			return $configuration;
		}
		
		/**
		 * @return integer
		 */
		public function getRichtextConfiguration()
		{
			return $this->richtextConfiguration;
		}
		
		/**
		 * @param string $richtextConfiguration
		 * @return Text
		 */
		public function setRichtextConfiguration($richtextConfiguration)
		{
			$this->richtextConfiguration = $richtextConfiguration;
			return $this;
		}
		
	}
  1. Extend \FluidTYPO3\Flux\ViewHelpers\Field\TextViewHelper
class TextViewHelper extends \FluidTYPO3\Flux\ViewHelpers\Field\TextViewHelper {
				
		public function initializeArguments()
		{
			
			parent::initializeArguments();
			
			$this->registerArgument(
				'richtextConfiguration',
				'string',
				'FlexForm-syntax "richtextConfiguration" definition, example: "minimal"',
				false,
				'default'
			);
			
		}
		
		/**
		 * @param RenderingContextInterface $renderingContext
		 * @param array $arguments
		 * @return Text
		 */
		public static function getComponent(RenderingContextInterface $renderingContext, array $arguments)
		{
			/** @var Text $text */
			$text = parent::getComponent($renderingContext,$arguments);
			
			$text->setRichtextConfiguration($arguments['richtextConfiguration']);
			
			return $text;
			
		}
		
	}
  1. Add overrides to ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\FluidTYPO3\Flux\Form\Field\Text::class] = ['className' => Vendor\Xclass\Field\Text::class];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\FluidTYPO3\Flux\ViewHelpers\Field\TextViewHelper::class] = ['className' => Vendor\ViewHelpers\TextViewHelper::class];
  1. Use richtextConfiguration in fluid like you would with flux >v9
  <flux:field.text
    name="description"
    label="Description"
    enableRichText="1"
    richtextConfiguration="full"
  />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment