Exemplo n.º 1
0
 /**
  * Creates a list item for one datasource.
  *
  * @param \Drupal\search_api\Datasource\DatasourceInterface|null $datasource
  *   The datasource, or NULL for general properties.
  *
  * @return array
  *   A render array representing the given datasource and, possibly, its
  *   attached properties.
  */
 protected function getDatasourceListItem(DatasourceInterface $datasource = NULL)
 {
     $item = array('#type' => 'container', '#attributes' => array('class' => array('container-inline')));
     $active = FALSE;
     $datasource_id = $datasource ? $datasource->getPluginId() : '';
     $active_datasource = $this->getParameter('datasource');
     if (isset($active_datasource)) {
         $active = $active_datasource == $datasource_id;
     }
     $url = $this->entity->toUrl('add-fields');
     if ($active) {
         $expand_link = array('#type' => 'link', '#title' => '(-) ', '#url' => $url);
     } else {
         $url->setOption('query', array('datasource' => $datasource_id));
         $expand_link = array('#type' => 'link', '#title' => '(+) ', '#url' => $url);
     }
     $item['expand_link'] = $expand_link;
     $label = $datasource ? Html::escape($datasource->label()) : $this->t('General');
     $item['label']['#markup'] = $label;
     if ($active) {
         $properties = $this->entity->getPropertyDefinitions($datasource_id ?: NULL);
         if ($properties) {
             $active_property_path = $this->getParameter('property_path', '');
             $base_url = clone $url;
             $base_url->setOption('query', array('datasource' => $datasource_id));
             $item['properties'] = $this->getPropertiesList($properties, $active_property_path, $base_url);
         }
     }
     return $item;
 }