/** * Adds sub-folder in folder. * @param array $data Contains additional fields (CREATED_BY, NAME, etc). * @param array $rights Rights (@see \Bitrix\Disk\RightsManager). * @param bool $generateUniqueName Generates unique name for object in directory. * @throws \Bitrix\Main\ArgumentException * @return null|static|Folder */ public function addSubFolder(array $data, array $rights = array(), $generateUniqueName = false) { $this->errorCollection->clear(); $this->checkRequiredInputParams($data, array('NAME')); if ($generateUniqueName) { $data['NAME'] = $this->generateUniqueName($data['NAME'], $this->id); } if (!$this->isUniqueName($data['NAME'], $this->id)) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FOLDER_MODEL_ERROR_NON_UNIQUE_NAME'), self::ERROR_NON_UNIQUE_NAME))); return null; } $data['PARENT_ID'] = $this->id; $data['STORAGE_ID'] = $this->storageId; $folderModel = Folder::add($data, $this->errorCollection); if (!$folderModel) { return null; } Driver::getInstance()->getRightsManager()->setAsNewLeaf($folderModel, $rights); return $folderModel; }
public static function add(array $data, ErrorCollection $errorCollection) { if (!is_subclass_of($data['ENTITY_TYPE'], ProxyType\Base::className())) { throw new SystemException('Invalid class for ProxyType. Must be subclass of ProxyType\\Base'); } $rootObjectData = array(); if (!empty($data['ROOT_OBJECT'])) { $rootObjectData = $data['ROOT_OBJECT']; unset($data['ROOT_OBJECT']); } $storage = parent::add($data, $errorCollection); if (!$storage) { return null; } $folderData = array_merge(array_intersect_key($rootObjectData, array('CREATE_TIME' => true, 'UPDATE_TIME' => true, 'XML_ID' => true)), array('NAME' => Ui\Text::correctFilename($storage->getName()), 'STORAGE_ID' => $storage->getId())); $folder = Folder::add($folderData, $errorCollection); if (!$folder) { return null; } $success = $storage->update(array('ROOT_OBJECT_ID' => $folder->getId())); if (!$success) { return null; } $storage->rootObject = $folder; $event = new Event(Driver::INTERNAL_MODULE_ID, "onAfterAddStorage", array($storage)); $event->send(); $storage->clearByTagCommonStorages(); return $storage; }