예제 #1
0
 /**
  * Creates a search item object by wrapping an existing complex data object.
  *
  * @param \Drupal\search_api\IndexInterface $index
  *   The item's search index.
  * @param \Drupal\Core\TypedData\ComplexDataInterface $original_object
  *   The original object to wrap.
  * @param string $id
  *   (optional) The item's (combined) ID. If not set, it will be determined
  *   with the \Drupal\search_api\Datasource\DatasourceInterface::getItemId()
  *   method of $datasource. In this case, $datasource must not be NULL.
  * @param \Drupal\search_api\Datasource\DatasourceInterface|null $datasource
  *   (optional) The datasource of the item. If not set, it will be determined
  *   from the ID and loaded from the index if needed.
  *
  * @return \Drupal\search_api\Item\ItemInterface
  *   A search item with the given values.
  *
  * @throws \InvalidArgumentException
  *   Thrown if both $datasource and $id are NULL.
  */
 public static function createItemFromObject(IndexInterface $index, ComplexDataInterface $original_object, $id = NULL, DatasourceInterface $datasource = NULL)
 {
     if (!isset($id)) {
         if (!isset($datasource)) {
             throw new \InvalidArgumentException('Need either an item ID or the datasource to create a search item from an object.');
         }
         $id = self::createCombinedId($datasource->getPluginId(), $datasource->getItemId($original_object));
     }
     $item = static::createItem($index, $id, $datasource);
     $item->setOriginalObject($original_object);
     return $item;
 }
예제 #2
0
 /**
  * Constructs an Item object.
  *
  * @param \Drupal\search_api\IndexInterface $index
  *   The item's search index.
  * @param string $id
  *   The ID of this item.
  * @param \Drupal\search_api\Datasource\DatasourceInterface|null $datasource
  *   (optional) The datasource of this item. If not set, it will be determined
  *   from the ID and loaded from the index.
  */
 public function __construct(IndexInterface $index, $id, DatasourceInterface $datasource = NULL)
 {
     $this->index = $index;
     $this->id = $id;
     if ($datasource) {
         $this->datasource = $datasource;
         $this->datasourceId = $datasource->getPluginId();
     }
 }
예제 #3
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;
 }
 /**
  * {@inheritdoc}
  */
 public function alterPropertyDefinitions(array &$properties, DatasourceInterface $datasource = NULL)
 {
     if ($datasource) {
         $entity_type = $datasource->getEntityTypeId();
         if (in_array($entity_type, array('node', 'comment'))) {
             $properties['status'] = ProxyProperty::create($properties['status'])->setLocked();
             if ($entity_type == 'node') {
                 $properties['uid'] = ProxyProperty::create($properties['uid'])->setLocked();
             }
         }
         return;
     }
     $definition = array('label' => $this->t('Node access information'), 'description' => $this->t('Data needed to apply node access.'), 'type' => 'string');
     $properties['search_api_node_grants'] = BasicProperty::createFromDefinition($definition)->setLocked()->setHidden();
 }