Example #1
0
 /**
  * Returns the alternate view template paths (a.k.a. template overrides in Joomla!-speak) for the given View name
  *
  * @param string $viewName The name of the view triggering this event
  *
  * @return array The template override paths
  */
 public function onGetViewTemplatePaths($viewName)
 {
     $container = $this->subject->getContainer();
     $application_name = $container->application_name;
     $component_name = 'com_' . strtolower($application_name);
     // That's the path in the site's current template containing template overrides
     $overridePath = Helper::getTemplateOverridePath($component_name, true);
     // The alternative view name (pluralised if the view is singular, singularised if the view is plural)
     $altViewName = Inflector::isPlural($viewName) ? Inflector::singularize($viewName) : Inflector::pluralize($viewName);
     // Remember, each path is pushed to the TOP of the path stack. This means that the least important directory
     // must go FIRST so that it ends add being added LAST.
     return array($overridePath . '/' . $altViewName, $overridePath . '/' . $viewName);
 }
Example #2
0
 /**
  * Determines the CRUD task to use based on the view name and HTTP verb used in the request.
  *
  * @return  string  The CRUD task (browse, read, edit, delete)
  */
 protected function getCrudTask()
 {
     // By default, a plural view means 'browse' and a singular view means 'edit'
     $view = $this->input->getCmd('view', null);
     $task = Inflector::isPlural($view) ? 'browse' : 'edit';
     // If the task is 'edit' but there's no logged in user switch to a 'read' task
     if ($task == 'edit' && !$this->container->userManager->getUser()->getId()) {
         $task = 'read';
     }
     // Check if there is an id passed in the request
     $id = $this->input->get('id', null, 'int');
     if ($id == 0) {
         $ids = $this->input->get('ids', array(), 'array');
         if (!empty($ids)) {
             $id = array_shift($ids);
         }
     }
     // Get the request HTTP verb
     if (!isset($_SERVER['REQUEST_METHOD'])) {
         $_SERVER['REQUEST_METHOD'] = 'GET';
     }
     $requestMethod = strtoupper($_SERVER['REQUEST_METHOD']);
     // Alter the task based on the verb
     switch ($requestMethod) {
         // POST and PUT result in a record being saved, as long as there is an ID
         case 'POST':
         case 'PUT':
             if ($id) {
                 $task = 'save';
             }
             break;
             // DELETE results in a record being deleted, as long as there is an ID
         // DELETE results in a record being deleted, as long as there is an ID
         case 'DELETE':
             if ($id) {
                 $task = 'delete';
             }
             break;
             // GET results in browse, edit or add depending on the ID
         // GET results in browse, edit or add depending on the ID
         case 'GET':
         default:
             // If it's an edit without an ID or ID=0, it's really an add
             if ($task == 'edit' && $id == 0) {
                 $task = 'add';
             }
             break;
     }
     return $task;
 }