Ejemplo n.º 1
0
 public function onAfterConstruct(DataModel &$model)
 {
     // This only applies to the front-end
     if (!$model->getContainer()->platform->isFrontend()) {
         return;
     }
     // Get the page parameters
     /** @var \JRegistry $params */
     $params = \JFactory::getApplication()->getPageParameters();
     // Extract the page parameter keys
     $asArray = $params->toArray();
     if (empty($asArray)) {
         // There are no keys; no point in going on.
         return;
     }
     $keys = array_keys($asArray);
     unset($asArray);
     // Loop all page parameter keys
     foreach ($keys as $key) {
         // This is the current model state
         $currentState = $model->getState($key);
         // This is the explicitly requested state in the input
         $explicitInput = $model->input->get($key, null, 'raw');
         // If the current state is empty and there's no explicit input we'll use the page parameters instead
         if (is_null($currentState) && is_null($explicitInput)) {
             $model->setState($key, $params->get($key));
         }
     }
 }