class PhotosEditController in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 src/Controller/PhotosEditController.php \Drupal\photos\Controller\PhotosEditController
- 8.4 src/Controller/PhotosEditController.php \Drupal\photos\Controller\PhotosEditController
Edit images and image details.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\photos\Controller\PhotosEditController
Expanded class hierarchy of PhotosEditController
File
- src/
Controller/ PhotosEditController.php, line 25
Namespace
Drupal\photos\ControllerView source
class PhotosEditController extends ControllerBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* The current path.
*
* @var \Drupal\Core\Path\CurrentPathStack
*/
protected $currentPath;
/**
* The FormBuilder object.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* The current request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The current route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Constructor.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
* @param \Drupal\Core\Path\CurrentPathStack $current_path
* The current path.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The current request stack.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*/
public function __construct(Connection $connection, CurrentPathStack $current_path, FormBuilderInterface $form_builder, ModuleHandlerInterface $module_handler, RendererInterface $renderer, RequestStack $request_stack, RouteMatchInterface $route_match) {
$this->connection = $connection;
$this->currentPath = $current_path;
$this->formBuilder = $form_builder;
$this->moduleHandler = $module_handler;
$this->renderer = $renderer;
$this->requestStack = $request_stack;
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('database'), $container
->get('path.current'), $container
->get('form_builder'), $container
->get('module_handler'), $container
->get('renderer'), $container
->get('request_stack'), $container
->get('current_route_match'));
}
/**
* A custom access check.
*
* @param \Drupal\node\NodeInterface $node
* The album node entity.
* @param \Drupal\photos\PhotosImageInterface $photos_image
* The photos_image entity.
*
* @return \Drupal\Core\Access\AccessResult
* The access result.
*/
public function access(NodeInterface $node, PhotosImageInterface $photos_image) {
if ($node && $photos_image) {
// Update cover.
if ($node
->getType() == 'photos' && $node
->access('update')) {
// Allowed to update album cover image.
return AccessResult::allowed();
}
else {
// Deny access.
return AccessResult::forbidden();
}
}
else {
return AccessResult::neutral();
}
}
/**
* Set album cover.
*
* @param \Drupal\node\NodeInterface $node
* The photo album node.
* @param \Drupal\photos\PhotosImageInterface $photos_image
* The photos_image entity.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* Redirect to destination or photo album node page.
*/
public function setAlbumCover(NodeInterface $node, PhotosImageInterface $photos_image) {
$nid = $node
->id();
$album_id = $this->connection
->query('SELECT album_id FROM {photos_image_field_data} WHERE id = :cover_id', [
':cover_id' => $photos_image
->id(),
])
->fetchField();
if ($album_id == $nid) {
$album = new PhotosAlbum($album_id);
$album
->setCover($photos_image
->id());
$get_destination = $this->requestStack
->getCurrentRequest()->query
->get('destination');
if ($get_destination) {
$goto = Url::fromUri('base:' . $get_destination)
->toString();
}
else {
$goto = $photos_image
->getAlbumUrl()
->toString();
}
return new RedirectResponse($goto);
}
else {
throw new NotFoundHttpException();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function | Returns a redirect response object for the specified route. | |
ControllerBase:: |
protected | function | Returns the state storage service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PhotosEditController:: |
protected | property | The database connection. | |
PhotosEditController:: |
protected | property | The current path. | |
PhotosEditController:: |
protected | property |
The FormBuilder object. Overrides ControllerBase:: |
|
PhotosEditController:: |
protected | property |
The module handler. Overrides ControllerBase:: |
|
PhotosEditController:: |
protected | property | The renderer. | |
PhotosEditController:: |
protected | property | The current request stack. | |
PhotosEditController:: |
protected | property | The current route match. | |
PhotosEditController:: |
public | function | A custom access check. | |
PhotosEditController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
PhotosEditController:: |
public | function | Set album cover. | |
PhotosEditController:: |
public | function | Constructor. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |