Skip to content

Instantly share code, notes, and snippets.

@NamelessCoder
Last active April 12, 2016 19:40

Revisions

  1. NamelessCoder revised this gist Apr 12, 2016. 1 changed file with 27 additions and 5 deletions.
    32 changes: 27 additions & 5 deletions ContentElementDefinitionProvider.php
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,51 @@
    <?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
    *
    * Manipulate current definitions. Return from this method the new
    * array of definitions
    * 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 removeContentElementDefinitions(array $currentDefinitions)
    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
    *
    * Manipulate current definitions. Return from this method the new
    * array of definitions
    * Add new content definitions. Return from this method the new
    * array of definitions that should be *added* to existing ones.
    *
    * @return ContentElementDefinition[]
    */
  2. NamelessCoder created this gist Apr 12, 2016.
    46 changes: 46 additions & 0 deletions ContentElementDefinitionProvider.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    <?php

    class ContentElementDefinitionProvider extends AbstractContentElementDefinitionProvider implements ContentDefinitionProviderInterface
    {

    /**
    * DEFINED ON INTERFACE
    *
    * Manipulate current definitions. Return from this method the new
    * array of definitions
    *
    * @param ContentElementDefinition[] $currentDefinitions
    * @return ContentElementDefinition[]
    */
    public function removeContentElementDefinitions(array $currentDefinitions)
    {
    $newDefinitions = $currentDefinitions;
    unset($newDefinitions['media'], $newDefinitions['shortcut']);
    return $newDefinitions;
    }

    /**
    * DEFINED ON INTERFACE
    *
    * Manipulate current definitions. Return from this method the new
    * array of definitions
    *
    * @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
    );
    }

    }