You are here

public function CmisCreateFolderForm::submitForm in CMIS API 8

Same name and namespace in other branches
  1. 8.2 src/Form/CmisCreateFolderForm.php \Drupal\cmis\Form\CmisCreateFolderForm::submitForm()
  2. 3.0.x src/Form/CmisCreateFolderForm.php \Drupal\cmis\Form\CmisCreateFolderForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/CmisCreateFolderForm.php, line 64

Class

CmisCreateFolderForm
Class CmisCreateFolder.

Namespace

Drupal\cmis\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $form_state
    ->setRedirect('cmis.cmis_repository_controller_browser', [
    'config' => $values['config'],
    'folder_id' => $values['folder_id'],
  ]);
  if (!empty($values['folder_name'])) {
    $repository = new \Drupal\cmis\Controller\CmisRepositoryController($values['config'], $values['folder_id']);
    if (!empty($repository
      ->getBrowser()
      ->getConnection()
      ->validObjectName($values['folder_name'], 'cmis:folder', $values['folder_id']))) {
      drupal_set_message($this
        ->t("The folder name @folder_name exists in folder.", [
        '@folder_name' => $values['folder_name'],
      ]), 'warning');
      return;
    }
    $session = $repository
      ->getBrowser()
      ->getConnection()
      ->getSession();
    $properties = array(
      \Dkd\PhpCmis\PropertyIds::OBJECT_TYPE_ID => 'cmis:folder',
      \Dkd\PhpCmis\PropertyIds::NAME => $values['folder_name'],
    );
    if (!empty($values['folder_description'])) {
      $properties[\Dkd\PhpCmis\PropertyIds::DESCRIPTION] = $values['folder_description'];
    }
    try {
      $session
        ->createFolder($properties, $session
        ->createObjectId($values['folder_id']));
      drupal_set_message($this
        ->t("The folder name @folder_name has been created.", [
        '@folder_name' => $values['folder_name'],
      ]));
    } catch (Exception $exc) {
      drupal_set_message($this
        ->t("The folder name @folder_name couldn't create.", [
        '@folder_name' => $values['folder_name'],
      ]), 'warning');
    }
  }
}