Elgg  Version master
PageOwnerService.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Page;
4 
9 use Elgg\Invoker;
11 
20 
24  protected $request;
25 
29  protected $entity_table;
30 
34  protected $events;
35 
39  protected $invoker;
40 
44  protected $page_owner_guid = 0;
45 
54  public function __construct(
59  ) {
60  $this->request = $request;
61  $this->entity_table = $entity_table;
62  $this->events = $events;
63  $this->invoker = $invoker;
64 
65  $this->page_owner_guid = $this->detectPageOwnerFromRoute();
66  }
67 
73  protected function detectPageOwnerFromRoute(): int {
74  $route = $this->request->getRoute();
75  if (!$route instanceof Route) {
76  return 0;
77  }
78 
79  $page_owner = $route->resolvePageOwner();
80  if (!$page_owner instanceof \ElggEntity) {
81  return 0;
82  }
83 
84  return $page_owner->guid;
85  }
86 
95  public function setPageOwnerGuid(int $guid = 0) {
96  if ($guid < 0) {
97  throw new RangeException(__METHOD__ . ' requires a positive integer.');
98  }
99 
100  $this->page_owner_guid = $guid;
101  }
102 
108  public function getPageOwnerGuid() {
109  return $this->page_owner_guid;
110  }
111 
117  public function getPageOwnerEntity(): ?\ElggEntity {
118  return $this->entity_table->get($this->getPageOwnerGuid());
119  }
120 }
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
$page_owner_guid
Elgg widget add action.
Definition: add.php:6
$page_owner
Definition: add.php:16
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
Entity table database service.
Definition: EntityTable.php:24
Events service.
Exception thrown to indicate range errors during program execution.
Elgg HTTP request.
Definition: Request.php:17
Invocation service.
Definition: Invoker.php:10
Holds page owner related functions.
getPageOwnerGuid()
Return the current page owner guid.
detectPageOwnerFromRoute()
Detects page owner from route.
__construct(Request $request, EntityTable $entity_table, EventsService $events, Invoker $invoker)
Constructor.
getPageOwnerEntity()
Returns the page owner entity.
setPageOwnerGuid(int $guid=0)
Sets a new page owner guid.
Route Wrapper.
Definition: Route.php:8