You are here

function vimeo_video_uploader_node_delete in Vimeo Video Uploader 8

Same name and namespace in other branches
  1. 8.4 vimeo_video_uploader.module \vimeo_video_uploader_node_delete()
  2. 7.2 vimeo_video_uploader.module \vimeo_video_uploader_node_delete()
  3. 7 vimeo_video_uploader.module \vimeo_video_uploader_node_delete()

Implements hook_node_delete().

File

./vimeo_video_uploader.module, line 115

Code

function vimeo_video_uploader_node_delete($node) {
  $config = \Drupal::config('vimeo_video_uploader.settings');
  $client_id = $config
    ->get('values.client_id');
  $client_secret = $config
    ->get('values.client_secret');
  $access_token = $config
    ->get('values.access_token');
  $content_type = $config
    ->get('values.content_type_select');
  if ($node
    ->bundle() == $content_type && !empty($node
    ->id())) {
    $field_embeddedvideo = $node
      ->get('field_embeddedvideo')->value;
    $video_id_val = substr($field_embeddedvideo, 17);
    if (!empty($video_id_val)) {
      $lib_ = new Vimeo($client_id, $client_secret, $access_token);
      try {
        $lib_
          ->request('/videos/' . $video_id_val, array(), 'DELETE');
      } catch (VimeoUploadException $e) {
        redirect_path('admin/content');
        $error_message = $e
          ->getMessage();
        drupal_set_message(t('Not Authorized...!' . $error_message), 'error');
        return;
      }
    }
  }
}