You are here

public function CmisRepositoryController::objectDelete in CMIS API 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Controller/CmisRepositoryController.php \Drupal\cmis\Controller\CmisRepositoryController::objectDelete()
  2. 8 src/Controller/CmisRepositoryController.php \Drupal\cmis\Controller\CmisRepositoryController::objectDelete()

Object delete popup.

Parameters

string $config: Entity label.

string $object_id: CMIS object id.

1 string reference to 'CmisRepositoryController::objectDelete'
cmis.routing.yml in ./cmis.routing.yml
cmis.routing.yml

File

src/Controller/CmisRepositoryController.php, line 168

Class

CmisRepositoryController
Class CmisRepositoryController.

Namespace

Drupal\cmis\Controller

Code

public function objectDelete($config = '', $object_id = '') {
  $parameters = \Drupal::request()->query
    ->all();
  if (!empty($parameters['type']) && !empty($config) && !empty($object_id) && (!empty($parameters['parent']) || !empty($parameters['query_string']))) {
    switch ($parameters['type']) {
      case 'browser':
        $redirect = $this
          ->redirect('cmis.cmis_repository_controller_browser', [
          'config' => $config,
        ]);
        break;
      case 'query':
        $parameters += [
          'config' => $config,
        ];
        $redirect = $this
          ->redirect('cmis.cmis_query_form_callback', [], [
          'query' => $parameters,
        ]);
        break;
      default:

        // Back to frontpage if not browser or not query.
        $redirect = new RedirectResponse('/');
    }
    $this
      ->setConnection($config);
    if ($this->connection) {
      $root = $this->connection
        ->getRootFolder();
      if ($root
        ->getId() != $object_id && ($current = $this->connection
        ->getObjectById($object_id))) {

        // Exists object and not root folder.
        $type = $current
          ->getBaseTypeId()
          ->__toString();
        $name = $current
          ->getName();
        $args = [
          '@type' => str_replace('cmis:', '', $type),
          '@name' => $name,
        ];
        $current
          ->delete(TRUE);
        $this
          ->messenger()
          ->addStatus($this
          ->t('The @type name @name has now been deleted.', $args));
        if ($parameters['type'] == 'browser') {
          $redirect = $this
            ->redirect('cmis.cmis_repository_controller_browser', [
            'config' => $config,
            'folder_id' => $parameters['parent'],
          ]);
        }
      }
      else {
        if ($root
          ->getId() != $object_id) {
          $this
            ->messenger()
            ->addWarning($this
            ->t('Could not delete object. Object is not exists in repository.'));
        }
        else {
          $this
            ->messenger()
            ->addWarning($this
            ->t('Could not delete root folder.'));
        }
      }
    }
  }
  else {
    $this
      ->messenger()
      ->addWarning($this
      ->t('Argument or parameter missed.'));

    // Back to frontpage.
    $redirect = new RedirectResponse('/');
  }
  return $redirect;
}