You are here

public function MediaDirectoriesController::directoryRename in Media Directories 8

Same name and namespace in other branches
  1. 3.x modules/media_directories_ui/src/Controller/MediaDirectoriesController.php \Drupal\media_directories_ui\Controller\MediaDirectoriesController::directoryRename()
  2. 2.x modules/media_directories_ui/src/Controller/MediaDirectoriesController.php \Drupal\media_directories_ui\Controller\MediaDirectoriesController::directoryRename()

Rename directory.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request.

Return value

\Drupal\Core\Ajax\AjaxResponse An AJAX response.

Throws

\Drupal\Core\Entity\EntityStorageException

1 string reference to 'MediaDirectoriesController::directoryRename'
media_directories_ui.routing.yml in modules/media_directories_ui/media_directories_ui.routing.yml
modules/media_directories_ui/media_directories_ui.routing.yml

File

modules/media_directories_ui/src/Controller/MediaDirectoriesController.php, line 222

Class

MediaDirectoriesController
Main controller class.

Namespace

Drupal\media_directories_ui\Controller

Code

public function directoryRename(Request $request) {
  $directory_id = (int) $request->request
    ->get('directory_id');
  $new_name = $request->request
    ->get('directory_new_name');
  $directory = Term::load($directory_id);
  $response = new AjaxResponse();
  if ($directory
    ->access('update')) {
    $directory
      ->setName($new_name);
    $directory
      ->save();
  }
  else {
    $this
      ->messenger()
      ->addError($this
      ->t('No permission found to rename this directory.'));
    $this
      ->addMessagesToResponse($response);
  }
  return $response;
}