openlayers-8.x-4.x-dev/src/OpenlayersPluginCollection.php
src/OpenlayersPluginCollection.php
<?php
namespace Drupal\openlayers;
use Drupal\Core\Plugin\DefaultLazyPluginCollection;
use Drupal\Component\Utility\Unicode;
/**
* A collection of Openlayers plugins.
*/
class OpenlayersPluginCollection extends DefaultLazyPluginCollection {
/**
* {@inheritdoc}
*
* @return \Drupal\image\ImageEffectInterface
*/
public function &get($instance_id) {
return parent::get($instance_id);
}
/**
* {@inheritdoc}
*/
public function sortHelper($aID, $bID) {
$a_label = $this->get($aID)->label();
$b_label = $this->get($bID)->label();
return Unicode::strcasecmp($a_label, $b_label);
}
public function getEntity($layerId) {
$config = $this->configurations[$layerId];
if (isset($config['entityId'])) {
$entityId = $config['entityId'];
} else {
\Drupal::messenger()->addError('Layer instance "' . $layerId . '" does not have a defined Entity ID.');
return null;
}
$entity = \Drupal::entityTypeManager()
->getStorage('openlayers_layer') // TODO - need to generalise for all Types (not just layers).
->load($entityId)
;
return $entity;
}
}
