當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::Load方法代碼示例

本文整理匯總了PHP中Drupal\file\Entity\File::Load方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::Load方法的具體用法?PHP File::Load怎麽用?PHP File::Load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\file\Entity\File的用法示例。


在下文中一共展示了File::Load方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: submitForm

  public function submitForm(array &$form, FormStateInterface $form_state) {
    // Process image cropping data.
    $form_state_values = $form_state->getValues();
    $fid = $form_state_values['fid'];
    if (\Drupal::moduleHandler()->moduleExists('image_widget_crop') && isset($form_state_values['image_crop'])) {
      $entity = \Drupal\file\Entity\File::Load($fid);
      if ($entity && is_array($form_state_values['image_crop']) && isset($form_state_values['image_crop']['crop_wrapper'])) {
        $this->submitFormCrops($form, $form_state, $form_state_values, $entity);
      }
    }
    // Save other image data.
    if (!empty($form_state_values['del'])) {
      if ($form_state->getValue('cover_fid') == $fid) {
        db_update('photos_album')
          ->fields(array(
            'fid' => 0
          ))
          ->condition('pid', $form_state->getValue('oldpid'))
          ->execute();
      }
      $msg = photos_file_del($fid, $form_state_values['filepath']);
      $uid = $form_state_values['uid'];
    }
    else {
      $wid = is_numeric($form_state_values['wid']) ? $form_state_values['wid'] : 0;
      db_update('photos_image')
        ->fields(array(
          'pid' => $form_state_values['pid'],
          'des' => $form_state_values['des'],
          'wid' => $wid
        ))
        ->condition('fid', $fid)
        ->execute();

      if ($form_state_values['title'] <> $form_state_values['oldtitle']) {
        db_update('photos_image')
          ->fields(array(
            'title' => $form_state_values['title']
          ))
          ->condition('fid', $fid)
          ->execute();
      }
      if ($form_state_values['pid'] <> $form_state->getValue('oldpid')) {
        $sub_select = db_select('photos_comment', 'v')
          ->fields('v', array('cid'))
          ->condition('v.fid', $fid)
          ->execute()->fetchCol();
        if (!empty($sub_select)) {
          db_update('comment')
            ->fields(array(
              'nid' => $form_state_values['pid']
            ))
            ->condition('cid', $sub_select, 'IN')
            ->execute();
        }
        $pid = $form_state_values['pid'];
        $uid = $form_state_values['uid'];
      }
    }
    // Clear image page cache.
    Cache::invalidateTags(array('photos:image:' . $fid));
    if ($nid = $form_state->getValue('nid')) {
      // Clear album page and node cache.
      Cache::invalidateTags(array('photos:album:' . $nid, 'node:' . $nid));
    }

    if (isset($pid) && $pid) {
      $pid;
      // @todo if image moved to new album also move attached comments to new node?
      // Get node object and update comment statistics.
      // @todo Argument 1 passed to Drupal\comment\CommentStatistics::update() must be an instance of Drupal\comment\CommentInterface.
      // $node = \Drupal\node\Entity\Node::load($nid);
      // \Drupal::service('comment.statistics')->update($node);
      photos_set_count('node_album', $pid);
      // Clear album page and node cache.
      Cache::invalidateTags(array('photos:album:' . $pid, 'node:' . $pid));
      photos_set_count('user_image', $uid);
    }

    // Image deleted or moved.
    if (isset($msg)) {
      $pid = $form_state->getValue('oldpid');
      drupal_set_message(t('Image deleted.'));
      // Redirect to album page.
      $nid = $form_state->getValue('nid');
      $url = Url::fromUri('base:photos/album/' . $nid);
      $form_state->setRedirectUrl($url);
    }
    // @todo redirect to image page?
    // @todo redirect to destination.
    drupal_set_message(t('Changes saved.'));


  // @todo check and implement the following for sub-albums.
  /*
    foreach ($form_state->getValue('photos') as $fid => $form_state_values) {
     if (!empty($form_state_values['del'])) {
       $msg[] = db_query('DELETE FROM {photos_node} WHERE fid = :fid AND nid = :nid',
         array(':fid' => $fid, ':nid' => $form_state->getValue('nid')));
     }
//.........這裏部分代碼省略.........
開發者ID:AshishNaik021,項目名稱:iimisac-d8,代碼行數:101,代碼來源:PhotosImageEditForm.php


注:本文中的Drupal\file\Entity\File::Load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。