Overview

Namespaces

  • DcGeneral
    • Clipboard
    • Contao
      • Callback
      • Compatibility
      • DataDefinition
        • Definition
      • Dca
        • Builder
          • Legacy
        • Definition
        • Palette
        • Populator
      • Event
      • View
        • Contao2BackendView
          • Event
    • Controller
    • Data
    • DataDefinition
      • Builder
      • Definition
        • Properties
        • View
          • Panel
      • ModelRelationship
      • Palette
        • Builder
          • Event
        • Condition
          • Palette
          • Property
    • EnvironmentPopulator
    • Event
    • Exception
    • Factory
      • Event
    • Panel
    • View
      • Event

Classes

  • BackendViewPopulator
  • DataProviderPopulator
  • ExtendedLegacyDcaPopulator
  • HardCodedPopulator
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * PHP version 5
  4:  * @package    generalDriver
  5:  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  6:  * @author     Stefan Heimes <stefan_heimes@hotmail.com>
  7:  * @author     Tristan Lins <tristan.lins@bit3.de>
  8:  * @copyright  The MetaModels team.
  9:  * @license    LGPL.
 10:  * @filesource
 11:  */
 12: 
 13: namespace DcGeneral\Contao\Dca\Populator;
 14: 
 15: use DcGeneral\Contao\DataDefinition\Definition\Contao2BackendViewDefinitionInterface;
 16: use DcGeneral\DataDefinition\Definition\BasicDefinitionInterface;
 17: use DcGeneral\DataDefinition\Definition\View\Panel\FilterElementInformationInterface;
 18: use DcGeneral\DataDefinition\Definition\View\Panel\LimitElementInformationInterface;
 19: use DcGeneral\DataDefinition\Definition\View\Panel\SearchElementInformationInterface;
 20: use DcGeneral\DataDefinition\Definition\View\Panel\SortElementInformationInterface;
 21: use DcGeneral\DataDefinition\Definition\View\Panel\SubmitElementInformationInterface;
 22: use DcGeneral\EnvironmentInterface;
 23: use DcGeneral\EnvironmentPopulator\AbstractEventDrivenEnvironmentPopulator;
 24: use DcGeneral\Exception\DcGeneralInvalidArgumentException;
 25: use DcGeneral\Panel\DefaultFilterElement;
 26: use DcGeneral\Panel\DefaultLimitElement;
 27: use DcGeneral\Panel\DefaultPanel;
 28: use DcGeneral\Panel\DefaultPanelContainer;
 29: use DcGeneral\Panel\DefaultSearchElement;
 30: use DcGeneral\Panel\DefaultSortElement;
 31: use DcGeneral\Panel\DefaultSubmitElement;
 32: use DcGeneral\Contao\View\Contao2BackendView\BackendViewInterface;
 33: use DcGeneral\Contao\View\Contao2BackendView\BaseView;
 34: use DcGeneral\Contao\View\Contao2BackendView\ListView;
 35: use DcGeneral\Contao\View\Contao2BackendView\ParentView;
 36: use DcGeneral\Contao\View\Contao2BackendView\TreeView;
 37: 
 38: /**
 39:  * Class BackendViewPopulator
 40:  *
 41:  * This class is the default fallback populator in the Contao Backend to instantiate a BackendView.
 42:  *
 43:  * @package DcGeneral\Contao\Dca\Populator
 44:  */
 45: class BackendViewPopulator extends AbstractEventDrivenEnvironmentPopulator
 46: {
 47:     const PRIORITY = 100;
 48: 
 49:     /**
 50:      * Create a view instance in the environment if none has been defined yet.
 51:      *
 52:      * @param EnvironmentInterface $environment The environment to populate.
 53:      *
 54:      * @return void
 55:      *
 56:      * @throws DcGeneralInvalidArgumentException Upon an unknown view mode has been encountered.
 57:      * @internal
 58:      */
 59:     protected function populateView(EnvironmentInterface $environment)
 60:     {
 61:         // Already populated or not in Backend? Get out then.
 62:         if ($environment->getView() || (TL_MODE != 'BE'))
 63:         {
 64:             return;
 65:         }
 66: 
 67:         $definition = $environment->getDataDefinition();
 68: 
 69:         if (!$definition->hasBasicDefinition())
 70:         {
 71:             return;
 72:         }
 73: 
 74:         $definition = $definition->getBasicDefinition();
 75: 
 76:         switch ($definition->getMode())
 77:         {
 78:             case BasicDefinitionInterface::MODE_FLAT:
 79:                 $view = new ListView();
 80:                 break;
 81:             case BasicDefinitionInterface::MODE_PARENTEDLIST:
 82:                 $view = new ParentView();
 83:                 break;
 84:             case BasicDefinitionInterface::MODE_HIERARCHICAL:
 85:                 $view = new TreeView();
 86:                 break;
 87:             default:
 88:                 throw new DcGeneralInvalidArgumentException('Unknown view mode encountered: ' . $definition->getMode());
 89:         }
 90: 
 91:         $view->setEnvironment($environment);
 92:         $environment->setView($view);
 93:     }
 94: 
 95:     /**
 96:      * Create a panel instance in the view if none has been defined yet.
 97:      *
 98:      * @param EnvironmentInterface $environment The environment to populate.
 99:      *
100:      * @return void
101:      *
102:      * @internal
103:      */
104:     protected function populatePanel(EnvironmentInterface $environment)
105:     {
106:         // Already populated or not in Backend? Get out then.
107:         if (!(($environment->getView() instanceof BaseView) && (TL_MODE == 'BE')))
108:         {
109:             return;
110:         }
111: 
112:         $definition = $environment->getDataDefinition();
113: 
114:         if (!$definition->hasDefinition(Contao2BackendViewDefinitionInterface::NAME))
115:         {
116:             return;
117:         }
118: 
119:         /** @var BackendViewInterface $view */
120:         $view = $environment->getView();
121: 
122:         // Already populated.
123:         if ($view->getPanel())
124:         {
125:             return;
126:         }
127: 
128:         $panel = new DefaultPanelContainer();
129:         $panel->setEnvironment($environment);
130:         $view->setPanel($panel);
131: 
132:         /** @var Contao2BackendViewDefinitionInterface $backendViewDefinition  */
133:         $backendViewDefinition = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
134: 
135:         /** @var \DcGeneral\DataDefinition\Definition\View\PanelLayoutInterface $panelLayout */
136:         $panelLayout = $backendViewDefinition->getPanelLayout();
137: 
138:         foreach ($panelLayout->getRows() as $panelKey => $row)
139:         {
140:             // We need a new panel.
141:             $panelRow = new DefaultPanel();
142: 
143:             $panel->addPanel($panelKey, $panelRow);
144: 
145:             foreach ($row as $element)
146:             {
147:                 if ($element instanceof FilterElementInformationInterface)
148:                 {
149:                     $panelElement = new DefaultFilterElement();
150:                     $panelElement->setPropertyName($element->getPropertyName());
151:                     $panelRow->addElement($element->getName(), $panelElement);
152:                 }
153:                 elseif ($element instanceof LimitElementInformationInterface)
154:                 {
155:                     $panelElement = new DefaultLimitElement();
156:                     $panelRow->addElement($element->getName(), $panelElement);
157:                 }
158:                 elseif ($element instanceof SearchElementInformationInterface)
159:                 {
160:                     $panelElement = new DefaultSearchElement();
161: 
162:                     foreach ($element->getPropertyNames() as $propName)
163:                     {
164:                         $panelElement->addProperty($propName);
165:                     }
166: 
167:                     $panelRow->addElement($element->getName(), $panelElement);
168:                 }
169:                 elseif ($element instanceof SortElementInformationInterface)
170:                 {
171:                     $panelElement = new DefaultSortElement();
172: 
173:                     foreach ($element->getPropertyNames() as $propName)
174:                     {
175:                         $panelElement->addProperty($propName, $element->getPropertyFlag($propName));
176:                     }
177: 
178:                     $panelRow->addElement($element->getName(), $panelElement);
179:                 }
180:                 elseif ($element instanceof SubmitElementInformationInterface)
181:                 {
182:                     $panelElement = new DefaultSubmitElement();
183:                     $panelRow->addElement($element->getName(), $panelElement);
184:                 }
185: 
186:             }
187:         }
188:     }
189: 
190:     /**
191:      * Create a view instance in the environment if none has been defined yet.
192:      *
193:      * @param EnvironmentInterface $environment The environment to populate.
194:      *
195:      * @return void
196:      */
197:     public function populate(EnvironmentInterface $environment)
198:     {
199:         $this->populateView($environment);
200: 
201:         $this->populatePanel($environment);
202:     }
203: }
204: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0