/** * Create an object instance for an export. * * @param string $object_type * The object type to look up. See openlayers_object_types() for a list of * available object types. * @param array|string|object $export * The exported object. * * @return ObjectInterface|Error * Returns the instance of the requested object or an instance of * Error on error. */ 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 @machine_name.'); $object = \Drupal::service('openlayers.Types')->createInstance('Error', $configuration); } if (isset($configuration['disabled']) && (bool) $configuration['disabled'] == 1) { $object->disabled = 1; } return $object->init(); }