ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilPlugin Class Reference
+ Inheritance diagram for ilPlugin:
+ Collaboration diagram for ilPlugin:

Public Member Functions

 getMessage ()
 
 __construct (\ilDBInterface $db, \ilComponentRepositoryWrite $component_repository, string $id)
 
 getPluginName ()
 
 getId ()
 
 getVersion ()
 Only very little classes seem to care about this: More...
 
 getDirectory ()
 Only very little classes seem to care about this: More...
 
 isActive ()
 Only very little classes seem to care about this: More...
 
 needsUpdate ()
 
 install ()
 
 uninstall ()
 
 activate ()
 This will update (if required) and activate the plugin. More...
 
 deactivate ()
 
 update ()
 
 loadLanguageModule ()
 Load language module for plugin. More...
 
 txt (string $a_var)
 Get Language Variable (prefix will be prepended automatically) More...
 
 getTemplate (string $a_template, bool $a_par1=true, bool $a_par2=true)
 ILIAS is moving towards UI components and plugins are expected to use these components. More...
 
 getStyleSheetLocation (string $a_css_file)
 ILIAS is moving towards UI components and plugins are expected to use these components. More...
 
 addBlockFile ($a_tpl, $a_var, $a_block, $a_tplname)
 ILIAS is moving towards UI components and plugins are expected to use these components. More...
 
 getGlobalScreenProviderCollection ()
 
 exchangeUIRendererAfterInitialization (\ILIAS\DI\Container $dic)
 This methods allows to replace the UI Renderer (see src/UI) of ILIAS after initialization by returning a closure returning a custom renderer. More...
 
 exchangeUIFactoryAfterInitialization (string $dic_key, \ILIAS\DI\Container $dic)
 This methods allows to replace some factory for UI Components (see src/UI) of ILIAS after initialization by returning a closure returning a custom factory. More...
 

Protected Member Functions

 init ()
 Object initialization. More...
 
 getPluginInfo ()
 
 getComponentInfo ()
 
 getPluginSlotInfo ()
 
 afterInstall ()
 If you cannot get rid of the requirement to use this, adjust the install method in your subclass instead. More...
 
 beforeUninstall ()
 If you cannot get rid of the requirement to use this, adjust the uninstall method in your subclass instead. More...
 
 afterUninstall ()
 If you cannot get rid of the requirement to use this, adjust the uninstall method in your subclass instead. More...
 
 beforeActivation ()
 If you cannot get rid of the requirement to use this, adjust the activate method in your subclass instead. More...
 
 afterActivation ()
 If you cannot get rid of the requirement to use this, adjust the activate method in your subclass instead. More...
 
 afterDeactivation ()
 If you cannot get rid of the requirement to use this, adjust the activate method in your subclass instead. More...
 
 updateDatabase ()
 
 beforeUpdate ()
 If you cannot get rid of the requirement to use this, adjust the update method in your subclass instead. More...
 
 afterUpdate ()
 
 getLanguageHandler ()
 
 buildLanguageHandler ()
 
 readEventListening ()
 
 clearEventListening ()
 

Protected Attributes

ilDBInterface $db
 
ilComponentRepositoryWrite $component_repository
 
string $id
 
ilPluginLanguage $language_handler = null
 
bool $lang_initialised = false
 
ProviderCollection $provider_collection
 
string $message = ''
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilPlugin::__construct ( \ilDBInterface  $db,
\ilComponentRepositoryWrite  $component_repository,
string  $id 
)

Definition at line 53 of file class.ilPlugin.php.

References $component_repository, $db, $id, ilComponentRepository\hasPluginId(), init(), and loadLanguageModule().

57  {
59  throw new \LogicException(
60  "You tried to instantiate a plugin with an inexisting id '$id'." .
61  "This is odd... Please use ilComponentFactory to instantiate plugins."
62  );
63  }
64 
65  $this->db = $db;
66  $this->component_repository = $component_repository;
67  $this->id = $id;
68 
69  $this->provider_collection = new PluginProviderCollection();
70 
71  // Fix for authentication plugins
72  $this->loadLanguageModule();
73 
74  // Custom initialisation for plugin.
75  $this->init();
76  }
loadLanguageModule()
Load language module for plugin.
hasPluginId(string $id)
Check if a plugin exists.
string $id
ilComponentRepositoryWrite $component_repository
init()
Object initialization.
ilDBInterface $db
+ Here is the call graph for this function:

Member Function Documentation

◆ activate()

ilPlugin::activate ( )

This will update (if required) and activate the plugin.

Definition at line 215 of file class.ilPlugin.php.

References afterActivation(), beforeActivation(), getId(), needsUpdate(), and update().

215  : bool
216  {
217  if ($this->needsUpdate() && !$this->update()) {
218  return false;
219  }
220 
221  if (!$this->beforeActivation()) {
222  return false;
223  }
224 
225  $this->component_repository->setActivation($this->getId(), true);
226  $this->afterActivation();
227 
228  return true;
229  }
beforeActivation()
If you cannot get rid of the requirement to use this, adjust the activate method in your subclass ins...
afterActivation()
If you cannot get rid of the requirement to use this, adjust the activate method in your subclass ins...
+ Here is the call graph for this function:

◆ addBlockFile()

ilPlugin::addBlockFile (   $a_tpl,
  $a_var,
  $a_block,
  $a_tplname 
)

ILIAS is moving towards UI components and plugins are expected to use these components.

Hence, this method will be removed.

Definition at line 399 of file class.ilPlugin.php.

References getDirectory().

399  : void
400  {
401  $a_tpl->addBlockFile(
402  $a_var,
403  $a_block,
404  $this->getDirectory() . "/templates/" . $a_tplname
405  );
406  }
getDirectory()
Only very little classes seem to care about this:
+ Here is the call graph for this function:

◆ afterActivation()

ilPlugin::afterActivation ( )
protected

If you cannot get rid of the requirement to use this, adjust the activate method in your subclass instead.

Definition at line 252 of file class.ilPlugin.php.

Referenced by activate().

252  : void
253  {
254  }
+ Here is the caller graph for this function:

◆ afterDeactivation()

ilPlugin::afterDeactivation ( )
protected

If you cannot get rid of the requirement to use this, adjust the activate method in your subclass instead.

Definition at line 260 of file class.ilPlugin.php.

Referenced by deactivate().

260  : void
261  {
262  }
+ Here is the caller graph for this function:

◆ afterInstall()

ilPlugin::afterInstall ( )
protected

If you cannot get rid of the requirement to use this, adjust the install method in your subclass instead.

Definition at line 186 of file class.ilPlugin.php.

Referenced by install().

186  : void
187  {
188  }
+ Here is the caller graph for this function:

◆ afterUninstall()

ilPlugin::afterUninstall ( )
protected

If you cannot get rid of the requirement to use this, adjust the uninstall method in your subclass instead.

Definition at line 203 of file class.ilPlugin.php.

Referenced by uninstall().

203  : void
204  {
205  }
+ Here is the caller graph for this function:

◆ afterUpdate()

ilPlugin::afterUpdate ( )
protected

Definition at line 324 of file class.ilPlugin.php.

Referenced by update().

324  : void
325  {
326  }
+ Here is the caller graph for this function:

◆ beforeActivation()

ilPlugin::beforeActivation ( )
protected

If you cannot get rid of the requirement to use this, adjust the activate method in your subclass instead.

Definition at line 243 of file class.ilPlugin.php.

Referenced by activate().

243  : bool
244  {
245  return true;
246  }
+ Here is the caller graph for this function:

◆ beforeUninstall()

ilPlugin::beforeUninstall ( )
protected

If you cannot get rid of the requirement to use this, adjust the uninstall method in your subclass instead.

Definition at line 194 of file class.ilPlugin.php.

Referenced by uninstall().

194  : bool
195  {
196  return true;
197  }
+ Here is the caller graph for this function:

◆ beforeUpdate()

ilPlugin::beforeUpdate ( )
protected

If you cannot get rid of the requirement to use this, adjust the update method in your subclass instead.

Definition at line 318 of file class.ilPlugin.php.

Referenced by update().

318  : bool
319  {
320  return true;
321  }
+ Here is the caller graph for this function:

◆ buildLanguageHandler()

ilPlugin::buildLanguageHandler ( )
protected

Definition at line 341 of file class.ilPlugin.php.

References getPluginInfo().

Referenced by getLanguageHandler().

342  {
343  return new ilPluginLanguage($this->getPluginInfo());
344  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearEventListening()

ilPlugin::clearEventListening ( )
protected

Definition at line 426 of file class.ilPlugin.php.

References getComponentInfo(), getDirectory(), getId(), getPluginInfo(), and getPluginSlotInfo().

Referenced by uninstall().

426  : void
427  {
428  $reader = new ilPluginReader(
429  $this->getDirectory() . '/plugin.xml',
430  $this->getComponentInfo()->getType(),
431  $this->getComponentInfo()->getName(),
432  $this->getPluginSlotInfo()->getId(),
433  $this->getPluginInfo()->getName()
434  );
435  $reader->clearEvents();
436  }
getDirectory()
Only very little classes seem to care about this:
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deactivate()

ilPlugin::deactivate ( )

Definition at line 231 of file class.ilPlugin.php.

References afterDeactivation(), and getId().

231  : bool
232  {
233  $this->component_repository->setActivation($this->getId(), false);
234  $this->afterDeactivation();
235 
236  return true;
237  }
afterDeactivation()
If you cannot get rid of the requirement to use this, adjust the activate method in your subclass ins...
+ Here is the call graph for this function:

◆ exchangeUIFactoryAfterInitialization()

ilPlugin::exchangeUIFactoryAfterInitialization ( string  $dic_key,
\ILIAS\DI\Container  $dic 
)

This methods allows to replace some factory for UI Components (see src/UI) of ILIAS after initialization by returning a closure returning a custom factory.

E.g:

if($key == "ui.factory.nameOfFactory"){ return function( $c){ return new CustomFactory($c['ui.signal_generator'],$c['ui.factory.maincontrols.slate']); }; }

Note: Note that plugins might conflict by replacing the same factory, so only use if you are sure, that no other plugin will do this for a given context.

Definition at line 484 of file class.ilPlugin.php.

484  : Closure
485  {
486  //This returns the callable of $c[$key] without executing it.
487  return $dic->raw($dic_key);
488  }
$dic
Definition: result.php:32

◆ exchangeUIRendererAfterInitialization()

ilPlugin::exchangeUIRendererAfterInitialization ( \ILIAS\DI\Container  $dic)

This methods allows to replace the UI Renderer (see src/UI) of ILIAS after initialization by returning a closure returning a custom renderer.

E.g:

return function( $c){ return new CustomRenderer(); };

Note: Note that plugins might conflict by replacing the renderer, so only use if you are sure, that no other plugin will do this for a given context.

Definition at line 464 of file class.ilPlugin.php.

464  : Closure
465  {
466  //This returns the callable of $c['ui.renderer'] without executing it.
467  return $dic->raw('ui.renderer');
468  }
$dic
Definition: result.php:32

◆ getComponentInfo()

ilPlugin::getComponentInfo ( )
protected

Definition at line 149 of file class.ilPlugin.php.

References getPluginInfo().

Referenced by clearEventListening(), getStyleSheetLocation(), and readEventListening().

150  {
151  return $this->getPluginInfo()->getComponent();
152  }
Simple value class for basic information about a component.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDirectory()

ilPlugin::getDirectory ( )

Only very little classes seem to care about this:

Definition at line 121 of file class.ilPlugin.php.

References getPluginInfo().

Referenced by addBlockFile(), clearEventListening(), getStyleSheetLocation(), getTemplate(), and readEventListening().

121  : string
122  {
123  return $this->getPluginInfo()->getPath();
124  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getGlobalScreenProviderCollection()

ilPlugin::getGlobalScreenProviderCollection ( )
final

◆ getId()

ilPlugin::getId ( )

◆ getLanguageHandler()

ilPlugin::getLanguageHandler ( )
protected

Definition at line 333 of file class.ilPlugin.php.

References $language_handler, and buildLanguageHandler().

Referenced by ilRepositoryObjectPlugin\getPrefix(), loadLanguageModule(), txt(), uninstall(), and update().

334  {
335  if ($this->language_handler === null) {
336  $this->language_handler = $this->buildLanguageHandler();
337  }
339  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilPluginLanguage $language_handler
buildLanguageHandler()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMessage()

ilPlugin::getMessage ( )
Returns
string

Definition at line 44 of file class.ilPlugin.php.

References $message.

44  : string
45  {
46  return $this->message;
47  }
string $message

◆ getPluginInfo()

ilPlugin::getPluginInfo ( )
protected

Definition at line 141 of file class.ilPlugin.php.

Referenced by buildLanguageHandler(), clearEventListening(), getComponentInfo(), getDirectory(), getId(), getPluginName(), getPluginSlotInfo(), getStyleSheetLocation(), getVersion(), isActive(), needsUpdate(), readEventListening(), update(), and updateDatabase().

141  : ilPluginInfo
142  {
143  return $this->component_repository
144  ->getPluginById(
145  $this->id
146  );
147  }
Simple value class for information about a plugin.
+ Here is the caller graph for this function:

◆ getPluginName()

ilPlugin::getPluginName ( )

Definition at line 95 of file class.ilPlugin.php.

References getPluginInfo().

Referenced by ilRepositoryObjectPlugin\beforeActivation(), ilPreviewRendererPlugin\getRendererClassInstance(), ilPageComponentPlugin\getUIClassInstance(), and ilDclFieldTypePlugin\install().

95  : string
96  {
97  return $this->getPluginInfo()->getName();
98  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPluginSlotInfo()

ilPlugin::getPluginSlotInfo ( )
protected

Definition at line 154 of file class.ilPlugin.php.

References getPluginInfo().

Referenced by clearEventListening(), getStyleSheetLocation(), and readEventListening().

155  {
156  return $this->getPluginInfo()->getPluginSlot();
157  }
Simple value class for basic information about a pluginslot.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStyleSheetLocation()

ilPlugin::getStyleSheetLocation ( string  $a_css_file)

ILIAS is moving towards UI components and plugins are expected to use these components.

Hence, this method will be removed.

Definition at line 382 of file class.ilPlugin.php.

References getComponentInfo(), getDirectory(), getPluginInfo(), getPluginSlotInfo(), and ilUtil\getStyleSheetLocation().

382  : string
383  {
384  $d2 = $this->getComponentInfo()->getId() . "_" . $this->getPluginSlotInfo()->getId() . "_" . $this->getPluginInfo()->getId();
385 
386  $css = ilUtil::getStyleSheetLocation("output", $a_css_file, $d2);
387  if (is_int(strpos($css, "Customizing"))) {
388  return $css;
389  }
390 
391  return $this->getDirectory() . "/templates/" . $a_css_file;
392  }
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
getDirectory()
Only very little classes seem to care about this:
+ Here is the call graph for this function:

◆ getTemplate()

ilPlugin::getTemplate ( string  $a_template,
bool  $a_par1 = true,
bool  $a_par2 = true 
)

ILIAS is moving towards UI components and plugins are expected to use these components.

Hence, this method will be removed.

Definition at line 373 of file class.ilPlugin.php.

References getDirectory().

373  : ilTemplate
374  {
375  return new ilTemplate($this->getDirectory() . "/templates/" . $a_template, $a_par1, $a_par2);
376  }
getDirectory()
Only very little classes seem to care about this:
+ Here is the call graph for this function:

◆ getVersion()

ilPlugin::getVersion ( )

Only very little classes seem to care about this:

Returns
string

Definition at line 111 of file class.ilPlugin.php.

References getPluginInfo().

111  : string
112  {
113  return (string) $this->getPluginInfo()->getAvailableVersion();
114  }
+ Here is the call graph for this function:

◆ init()

ilPlugin::init ( )
protected

Object initialization.

Can be overwritten by plugin class (and should be made protected)

TODO: Maybe this should be removed or be documented better. This is called during __construct. If this contains expensive stuff this will be bad for overall system performance, because Plugins tend to be constructed a lot.

Definition at line 86 of file class.ilPlugin.php.

Referenced by __construct().

86  : void
87  {
88  }
+ Here is the caller graph for this function:

◆ install()

ilPlugin::install ( )

Definition at line 164 of file class.ilPlugin.php.

References afterInstall().

164  : void
165  {
166  $this->afterInstall();
167  }
afterInstall()
If you cannot get rid of the requirement to use this, adjust the install method in your subclass inst...
+ Here is the call graph for this function:

◆ isActive()

ilPlugin::isActive ( )

Only very little classes seem to care about this:

  • Services/Component/classes/class.ilObjComponentSettingsGUI.php
  • Services/Repository/classes/class.ilRepositoryObjectPluginSlot.php

Definition at line 131 of file class.ilPlugin.php.

References getPluginInfo().

131  : bool
132  {
133  return $this->getPluginInfo()->isActive();
134  }
+ Here is the call graph for this function:

◆ loadLanguageModule()

ilPlugin::loadLanguageModule ( )

Load language module for plugin.

Just use txt, this will automatically load the language module.

Definition at line 351 of file class.ilPlugin.php.

References getLanguageHandler().

Referenced by __construct().

351  : void
352  {
353  $this->getLanguageHandler()->loadLanguageModule();
354  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ needsUpdate()

ilPlugin::needsUpdate ( )

Definition at line 136 of file class.ilPlugin.php.

References getPluginInfo().

Referenced by activate().

136  : bool
137  {
138  return $this->getPluginInfo()->isUpdateRequired();
139  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readEventListening()

ilPlugin::readEventListening ( )
protected

Definition at line 413 of file class.ilPlugin.php.

References getComponentInfo(), getDirectory(), getId(), getPluginInfo(), and getPluginSlotInfo().

Referenced by update().

413  : void
414  {
415  $reader = new ilPluginReader(
416  $this->getDirectory() . '/plugin.xml',
417  $this->getComponentInfo()->getType(),
418  $this->getComponentInfo()->getName(),
419  $this->getPluginSlotInfo()->getId(),
420  $this->getPluginInfo()->getName()
421  );
422  $reader->clearEvents();
423  $reader->startParsing();
424  }
getDirectory()
Only very little classes seem to care about this:
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ txt()

ilPlugin::txt ( string  $a_var)

Get Language Variable (prefix will be prepended automatically)

Definition at line 359 of file class.ilPlugin.php.

References getLanguageHandler().

Referenced by ilTestExportPlugin\getFormat().

359  : string
360  {
361  return $this->getLanguageHandler()->txt($a_var);
362  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ uninstall()

ilPlugin::uninstall ( )

Definition at line 169 of file class.ilPlugin.php.

References afterUninstall(), beforeUninstall(), clearEventListening(), getId(), and getLanguageHandler().

169  : bool
170  {
171  if (!$this->beforeUninstall()) {
172  return false;
173  }
174 
175  $this->getLanguageHandler()->uninstall();
176  $this->clearEventListening();
177  $this->component_repository->removeStateInformationOf($this->getId());
178  $this->afterUninstall();
179  return true;
180  }
beforeUninstall()
If you cannot get rid of the requirement to use this, adjust the uninstall method in your subclass in...
afterUninstall()
If you cannot get rid of the requirement to use this, adjust the uninstall method in your subclass in...
+ Here is the call graph for this function:

◆ update()

ilPlugin::update ( )

Definition at line 269 of file class.ilPlugin.php.

References $DIC, $ilDB, afterUpdate(), beforeUpdate(), getId(), getLanguageHandler(), getPluginInfo(), readEventListening(), and updateDatabase().

Referenced by activate(), and ilObjComponentSettingsGUI\update().

269  : bool
270  {
271  global $DIC;
272  $ilDB = $DIC->database();
273 
274  $result = $this->beforeUpdate();
275  if ($result === false) {
276  return false;
277  }
278 
279  // Load language files
280  $this->getLanguageHandler()->updateLanguages();
281 
282  // DB update
283  $db_version = $this->updateDatabase();
284 
285  $this->readEventListening();
286 
287  // set last update version to current version
288  $this->component_repository->setCurrentPluginVersion(
289  $this->getPluginInfo()->getId(),
290  $this->getPluginInfo()->getAvailableVersion(),
291  $db_version
292  );
293  $this->afterUpdate();
294 
295  return true;
296  }
global $DIC
Definition: feed.php:28
beforeUpdate()
If you cannot get rid of the requirement to use this, adjust the update method in your subclass inste...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateDatabase()

ilPlugin::updateDatabase ( )
protected

Definition at line 298 of file class.ilPlugin.php.

References $DIC, $ilDB, $lng, and getPluginInfo().

Referenced by update().

298  : int
299  {
300  global $DIC;
301  $ilDB = $DIC->database();
302  $lng = $DIC->language();
303 
304  $dbupdate = new ilPluginDBUpdate(
305  $this->db,
306  $this->getPluginInfo()
307  );
308 
309  $dbupdate->applyUpdate();
310 
311  return $dbupdate->getCurrentVersion();
312  }
$lng
Database Update class.
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $component_repository

◆ $db

ilDBInterface ilPlugin::$db
protected

Definition at line 33 of file class.ilPlugin.php.

Referenced by __construct(), and ilRepositoryObjectPlugin\beforeActivation().

◆ $id

string ilPlugin::$id
protected

Definition at line 35 of file class.ilPlugin.php.

Referenced by __construct().

◆ $lang_initialised

bool ilPlugin::$lang_initialised = false
protected

Definition at line 37 of file class.ilPlugin.php.

◆ $language_handler

ilPluginLanguage ilPlugin::$language_handler = null
protected

Definition at line 36 of file class.ilPlugin.php.

Referenced by getLanguageHandler().

◆ $message

string ilPlugin::$message = ''
protected

Definition at line 39 of file class.ilPlugin.php.

Referenced by getMessage().

◆ $provider_collection

ProviderCollection ilPlugin::$provider_collection
protected

Definition at line 38 of file class.ilPlugin.php.

Referenced by getGlobalScreenProviderCollection().


The documentation for this class was generated from the following file: