You are here

public static function Openlayers::load in Openlayers 7.3

Create an object instance for an export.

Parameters

string $object_type: The object type to look up. See openlayers_object_types() for a list of available object types.

array|string|object $export: The exported object.

Return value

ObjectInterface|Error Returns the instance of the requested object or an instance of Error on error.

65 calls to Openlayers::load()
Cluster::optionsToObjects in src/Plugin/Source/Cluster/Cluster.php
Return a flat array containing Openlayers Objects from the options array.
GeofieldWidget::optionsToObjects in modules/openlayers_geofield/src/Plugin/Component/GeofieldWidget/GeofieldWidget.php
Return a flat array containing Openlayers Objects from the options array.
Group::optionsForm in src/Plugin/Layer/Group/Group.php
@TODO What is this return? If it is the form, why is form by reference?
Group::optionsToObjects in src/Plugin/Layer/Group/Group.php
Return a flat array containing Openlayers Objects from the options array.
LayerSwitcher::optionsForm in src/Plugin/Control/LayerSwitcher/LayerSwitcher.php
@TODO What is this return? If it is the form, why is form by reference?

... See full list

File

src/Openlayers.php, line 106
Contains Openlayers.

Class

Openlayers
Class Openlayers.

Namespace

Drupal\openlayers

Code

public static function load($object_type = NULL, $export) {

  /** @var \Drupal\openlayers\Types\ObjectInterface $object */
  $object = NULL;
  $configuration = array();
  $object_type = drupal_ucfirst(drupal_strtolower(check_plain($object_type)));
  if (is_array($export)) {
    $configuration = $export;
  }
  if (is_object($export) && $export instanceof \StdClass) {
    $array_object = new \ArrayObject($export);
    $configuration = $array_object
      ->getArrayCopy();
  }
  if (is_object($export) && $export instanceof ObjectInterface) {
    return $export;
  }
  if (is_string($export)) {
    $configuration = (array) Openlayers::loadExportable($object_type, $export);
  }
  if (is_array($configuration) && isset($configuration['factory_service'])) {

    // Bail out if the base service can't be found - likely due a registry
    // rebuild.
    if (!\Drupal::hasService('openlayers.Types')) {
      return NULL;
    }
    list($plugin_manager_id, $plugin_id) = explode(':', $configuration['factory_service'], 2);
    if (\Drupal::hasService($plugin_manager_id)) {
      $plugin_manager = \Drupal::service($plugin_manager_id);
      if ($plugin_manager
        ->hasDefinition($plugin_id)) {
        $object = $plugin_manager
          ->createInstance($plugin_id, $configuration);
      }
      else {
        $configuration += array(
          'type' => $object_type,
          'errorMessage' => 'Unable to load @type @machine_name',
        );
        $object = \Drupal::service('openlayers.Types')
          ->createInstance('Error', $configuration);
      }
    }
    else {
      $configuration += array(
        'type' => $object_type,
        'errorMessage' => 'Service <em>@service</em> doesn\'t exists, unable to load @type @machine_name',
      );
      $object = \Drupal::service('openlayers.Types')
        ->createInstance('Error', $configuration);
    }
  }
  else {
    $configuration += array(
      'type' => $object_type,
      'name' => 'Error',
      'description' => 'Error',
      'factory_service' => '',
      'machine_name' => $export,
      'errorMessage' => 'Unable to load CTools exportable @type (<em>@machine_name</em>).',
    );
    $object = \Drupal::service('openlayers.Types')
      ->createInstance('Error', $configuration);
  }
  if (isset($configuration['disabled']) && (bool) $configuration['disabled'] == 1) {
    $object->disabled = 1;
  }
  return $object
    ->init();
}