本文整理汇总了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')));
}
//.........这里部分代码省略.........