Skip to content

Instantly share code, notes, and snippets.

@NamelessCoder
Last active April 12, 2016 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NamelessCoder/cfd999804ba385267a387d4abf33edcf to your computer and use it in GitHub Desktop.
Save NamelessCoder/cfd999804ba385267a387d4abf33edcf to your computer and use it in GitHub Desktop.
<?php
/**
* Content Element Definition Provider
*
* Contains methods to either remove/change or add
* content definitions to the new content wizard
* and content type selectors.
*
* Same instance is used for removing and adding
* definitions (for performance and in case it
* needs an internal state for some reason).
*
* To generate the final list of content element
* definitions that are available, every Provider
* must be consulted in the order they were registered.
*
* A default Provider can be shipped which reads
* available definitions from pageTSconfig and has
* an empty modifyContentElementDefinitions() method.
*/
class ContentElementDefinitionProvider extends AbstractContentElementDefinitionProvider implements ContentDefinitionProviderInterface
{
/**
* DEFINED ON INTERFACE
*
* Remove from or change in current definitions. Return from this method the new
* array of definitions after removing unwanted or changing wanted definitions.
*
* @param ContentElementDefinition[] $currentDefinitions
* @return ContentElementDefinition[]
*/
public function modifyContentElementDefinitions(array $currentDefinitions)
{
$newDefinitions = $currentDefinitions;
// removing definitions
unset($newDefinitions['media'], $newDefinitions['shortcut']);
// changing definitions
$newDefinitions['text']->setIcon('mycooltexticon.png');
return $newDefinitions;
}
/**
* DEFINED ON INTERFACE
*
* Add new content definitions. Return from this method the new
* array of definitions that should be *added* to existing ones.
*
* @return ContentElementDefinition[]
*/
public function addContentElementDefinitions()
{
$existingGroup = $this->getExistingContentElementDefinitionGroupByName('general');
$newContentDefinitionOne = new ContentElementDefinition();
$newContentDefinitionOne->setContentElementDefinitionGroup($existingGroup);
$newContentDefinitionOne->setCType('my_customtype');
$newContentDefinitionOne->setIcon('...');
$newContentDefinitionOne = new ContentElementDefinition();
$newContentDefinitionTwo->setContentElementDefinitionGroup(new ContentElementDefinitionGroup('mynewgroup'));
$newContentDefinitionTwo->setCType('...');
return array(
$newContentDefinitionOne,
$newContentDefinitionTwo
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment