Open Data Catalog v2.0.0
SchemaPropertiesHelper.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Drupal\metastore;
4 
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
7 
13 class SchemaPropertiesHelper implements ContainerInjectionInterface {
14 
20  protected $schemaRetriever;
21 
27  public static function create(ContainerInterface $container) {
28  return new static(
29  $container->get('dkan.metastore.schema_retriever')
30  );
31  }
32 
37  $this->schemaRetriever = $schemaRetriever;
38  }
39 
46  public function retrieveSchemaProperties(): array {
47  // Create a json object from our schema.
48  $schema = $this->schemaRetriever->retrieve('dataset');
49  $schema_object = json_decode($schema);
50 
51  // Build a list of the schema properties' title and description.
52  $property_list = [];
53  foreach ($schema_object->properties as $property_id => $property_object) {
54  if (isset($property_object->title)) {
55  $property_list[$property_id] = "{$property_object->title} ({$property_id})";
56  }
57  else {
58  $property_list[$property_id] = ucfirst($property_id);
59  }
60  }
61 
62  return $property_list;
63  }
64 
65 }
Drupal\metastore
Drupal\metastore\SchemaPropertiesHelper\retrieveSchemaProperties
retrieveSchemaProperties()
Definition: SchemaPropertiesHelper.php:46
Drupal\metastore\SchemaPropertiesHelper\__construct
__construct(SchemaRetriever $schemaRetriever)
Definition: SchemaPropertiesHelper.php:36
Drupal\metastore\SchemaPropertiesHelper
Definition: SchemaPropertiesHelper.php:13
Drupal\metastore\SchemaPropertiesHelper\create
static create(ContainerInterface $container)
Definition: SchemaPropertiesHelper.php:27
Drupal\metastore\SchemaPropertiesHelper\$schemaRetriever
$schemaRetriever
Definition: SchemaPropertiesHelper.php:20
Drupal\metastore\SchemaRetriever
Definition: SchemaRetriever.php:13