Exemplo n.º 1
0
 /**
  * Constructs a FacetSourceEditForm.
  *
  * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
  *   The entity type manager.
  * @param \Drupal\facets\UrlProcessor\UrlProcessorPluginManager $url_processor_plugin_manager
  *   The url processor plugin manager.
  */
 public function __construct(EntityTypeManagerInterface $entity_type_manager, UrlProcessorPluginManager $url_processor_plugin_manager)
 {
     $facet_source_storage = $entity_type_manager->getStorage('facets_facet_source');
     $this->urlProcessorPluginManager = $url_processor_plugin_manager;
     // Make sure we remove colons from the source id, those are disallowed in
     // the entity id.
     $source_id = $this->getRequest()->get('source_id');
     $source_id = str_replace(':', '__', $source_id);
     $facet_source = $facet_source_storage->load($source_id);
     if ($facet_source instanceof FacetSource) {
         $this->setEntity($facet_source);
     } else {
         // We didn't have a facet source config entity yet for this facet source
         // plugin, so we create it on the fly.
         $facet_source = new FacetSource(['id' => $source_id, 'name' => $this->getRequest()->get('source_id')], 'facets_facet_source');
         $facet_source->save();
         $this->setEntity($facet_source);
     }
     $this->setModuleHandler(\Drupal::moduleHandler());
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getFacetSourceConfig()
 {
     // Return the facet source config object, if it's already set on the facet.
     if ($this->facetSourceConfig instanceof FacetSource) {
         return $this->facetSourceConfig;
     }
     $storage = \Drupal::entityTypeManager()->getStorage('facets_facet_source');
     $source_id = str_replace(':', '__', $this->facet_source_id);
     // Load and return the facet source config object from the storage.
     $facet_source = $storage->load($source_id);
     if ($facet_source instanceof FacetSource) {
         $this->facetSourceConfig = $facet_source;
         return $this->facetSourceConfig;
     }
     // We didn't have a facet source config entity yet for this facet source
     // plugin, so we create it on the fly.
     $facet_source = new FacetSource(['id' => $source_id, 'name' => $this->facet_source_id], 'facets_facet_source');
     $facet_source->save();
     $this->facetSourceConfig = $facet_source;
     return $this->facetSourceConfig;
 }