/** * Create a block position. * * @param string[] $args { * @type string $name name of the position * @type string $description description of the position * </ul> * * @return int|bool position ID on success, false on failure. * * @throws \InvalidArgumentException Thrown if invalid parameters are received in $args * @throws AccessDeniedException Thrown if the user doesn't have permission to create the block position * @throws \RuntimeException Thrown if a block position with the same name already exists */ public function createposition($args) { // Argument check if (!isset($args['name']) || !strlen($args['name']) || !isset($args['description'])) { throw new \InvalidArgumentException(__('Invalid arguments array received')); } // Security check if (!System::isInstalling() && !SecurityUtil::checkPermission('ZikulaBlocksModule::position', "{$args['name']}::", ACCESS_ADD)) { throw new AccessDeniedException(); } $positions = ModUtil::apiFunc('ZikulaBlocksModule', 'user', 'getallpositions'); if (isset($positions) && is_array($positions)) { foreach ($positions as $position) { if ($position['name'] == $args['name']) { throw new \RuntimeException($this->__('Error! There is already a block position with the name you entered.')); } } } $item = new BlockPositionEntity(); $item->merge($args); $this->entityManager->persist($item); $this->entityManager->flush(); // Return the id of the newly created item to the calling process return $item['pid']; }