public function PhotosImageEditForm::form in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 src/Form/PhotosImageEditForm.php \Drupal\photos\Form\PhotosImageEditForm::form()
Gets the actual form array to be built.
Overrides ContentEntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ PhotosImageEditForm.php, line 113
Class
- PhotosImageEditForm
- Defines a form to edit images.
Namespace
Drupal\photos\FormCode
public function form(array $form, FormStateInterface $form_state) {
/** @var \Drupal\photos\PhotosImageInterface $photosImage */
$photosImage = $this->entity;
// @todo phase out type (no more sub-albums...).
$type = 'album';
$user = $this
->currentUser();
$form['#title'] = $this
->t('Edit @title', [
'@title' => $photosImage
->getTitle(),
]);
// Changed must be sent to the client, for later overwrite error checking.
$form['changed'] = [
'#type' => 'hidden',
'#default_value' => $photosImage
->getChangedTime(),
];
// Get node object.
$node = $this->entityTypeManager
->getStorage('node')
->load($photosImage
->getAlbumId());
$nid = $node
->id();
$cover = [];
if (isset($node->album) && isset($node->album['cover_id']) && !empty($node->album['cover_id'])) {
$photos_album = new PhotosAlbum($node
->id());
$cover = $photos_album
->getCover($node->album['cover_id']);
$cover['id'] = $node->album['cover_id'];
}
$photosImage->info = [
'cover' => $cover,
'pid' => $node
->id(),
'title' => $node
->getTitle(),
'uid' => $node
->getOwnerId(),
];
// @todo build imageView?
$imageView = [];
$imageView['photos_image'] = $photosImage;
// Album.
$album_update = '';
if ($photosImage && $user
->id() != $photosImage->info['uid']) {
$title = isset($photosImage->info['title']) ? $photosImage->info['title'] : '';
$album_update = [
$nid,
$photosImage->info['title'],
];
}
$uid = $photosImage ? $photosImage
->getOwnerId() : $user
->id();
$form['old_uid'] = [
'#type' => 'hidden',
'#default_value' => $uid,
];
// $albumOptions = PhotosAlbum::userAlbumOptions($uid, $album_update);
if (isset($node->album) && isset($node->album['cover_id'])) {
$form['cover_id'] = [
'#type' => 'hidden',
'#default_value' => $node->album['cover_id'],
];
}
$form['old_album_id'] = [
'#type' => 'hidden',
'#default_value' => $nid,
];
$form['nid'] = [
'#type' => 'hidden',
'#default_value' => $nid,
];
// $form['type'] = ['#type' => 'hidden', '#value' => $type];
$account = $this->entityTypeManager
->getStorage('user')
->load($photosImage
->getOwnerId());
$imageView['href'] = 'photos/' . $photosImage
->getAlbumId() . '/' . $photosImage
->id();
$item = [];
if ($type == 'album' && (!isset($cover['id']) || isset($cover['id']) && $photosImage
->id() != $cover['id'])) {
// Set cover link.
$cover_url = Url::fromRoute('photos.album.update.cover', [
'node' => $photosImage
->getAlbumId(),
'photos_image' => $photosImage
->id(),
], [
'attributes' => [
'target' => '_blank',
],
]);
$item[] = Link::fromTextAndUrl($this
->t('Set to Cover'), $cover_url);
}
// @todo counts.
$form['cover_items'] = [
'#theme' => 'item_list',
'#items' => $item,
];
$username = [
'#theme' => 'username',
'#account' => $account,
];
$upload_info = $this
->t('Uploaded on @time by @name', [
'@name' => $this->renderer
->renderPlain($username),
'@time' => $this->dateFormatter
->format($photosImage
->getCreatedTime(), 'short'),
]);
// @todo test moving image with album reference field.
$form['time']['#markup'] = $upload_info;
$form['oldtitle'] = [
'#type' => 'hidden',
'#default_value' => $photosImage
->getTitle(),
];
return parent::form($form, $form_state);
}