/** * Add a command * * Disable the menubar only for singular views that are editable. * * @param string $name The command name * @param mixed $config Parameters to be passed to the command * @return KControllerToolbarInterface */ public function addCommand($name, $config = array()) { $command = parent::addCommand($name, $config); $controller = $this->getController(); if ($controller->isEditable() && KStringInflector::isSingular($controller->getView()->getName())) { $command->disabled = true; } return $this; }
/** * Create an entity or a collection instance * * @param KObjectConfigInterface $config A KObjectConfig object with configuration options * @param KObjectManagerInterface $manager A ObjectInterface object * @return KEventPublisher */ public static function getInstance(KObjectConfigInterface $config, KObjectManagerInterface $manager) { $name = $config->object_identifier->name; if (KStringInflector::isSingular($name)) { $class = 'KModelEntityRow'; } else { $class = 'KModelEntityRowset'; } $instance = new $class($config); return $instance; }
/** * Generic read action, fetches an item * * @param KControllerContextInterface $context A command context object * @throws KControllerExceptionResourceNotFound * @return KModelEntityInterface */ protected function _actionRead(KControllerContextInterface $context) { //Request if ($this->getIdentifier()->domain === 'admin') { if ($this->isEditable() && KStringInflector::isSingular($this->getView()->getName())) { //Use JInput as we do not pass the request query back into the Joomla context JFactory::getApplication()->input->set('hidemainmenu', 1); } } return parent::_actionRead($context); }
/** * Method to set a model object attached to the controller * * @param mixed $model An object that implements KObjectInterface, KObjectIdentifier object * or valid identifier string * @return KControllerView */ public function setModel($model) { if (!$model instanceof KModelInterface) { if (is_string($model) && strpos($model, '.') === false) { // Model names are always plural if (KStringInflector::isSingular($model)) { $model = KStringInflector::pluralize($model); } $identifier = $this->getIdentifier()->toArray(); $identifier['path'] = array('model'); $identifier['name'] = $model; $identifier = $this->getIdentifier($identifier); } else { $identifier = $this->getIdentifier($model); } $model = $identifier; } $this->_model = $model; return $this->_model; }
/** * @dataProvider providePlurals */ public function testIsSingular($singular, $plural) { $this->assertTrue(KStringInflector::isSingular($singular)); }