diff --git a/src/Entity/Index.php b/src/Entity/Index.php index 70b54b8..54826fc 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -756,7 +756,7 @@ class Index extends ConfigEntityBase implements IndexInterface { /** @var \Drupal\search_api\Item\AdditionalFieldInterface $additional_field */ $additional_field = $this->fields[0]['additional fields'][$property_path]; $additional_field->setEnabled(TRUE); - $additional_field->setLocked(TRUE); + $additional_field->setLocked(); } } } @@ -809,11 +809,12 @@ class Index extends ConfigEntityBase implements IndexInterface { // To make it possible to lock fields that are, technically, nested, use // the original $property for this check. if ($original_property instanceof PropertyInterface) { - $field->setLocked($original_property->isLocked()); + $field->setIndexedLocked($original_property->isIndexedLocked()); + $field->setTypeLocked($original_property->isTypeLocked()); $field->setHidden($original_property->isHidden()); } $this->fields[0]['fields'][$key] = $field; - if (isset($field_options[$key]) || $field->isLocked()) { + if (isset($field_options[$key]) || $field->isIndexedLocked()) { $field->setIndexed(TRUE); if (isset($field_options[$key])) { $field->setType($field_options[$key]['type']); @@ -1226,7 +1227,7 @@ class Index extends ConfigEntityBase implements IndexInterface { $datasource_ids = array_merge(array(NULL), $this->getDatasourceIds()); foreach ($datasource_ids as $datasource_id) { foreach ($this->getPropertyDefinitions($datasource_id) as $key => $property) { - if ($property instanceof PropertyInterface && $property->isLocked()) { + if ($property instanceof PropertyInterface && $property->isIndexedLocked()) { $settings = $property->getFieldSettings(); if (empty($settings['type'])) { $mapping = Utility::getFieldTypeMapping(); diff --git a/src/Form/IndexFieldsForm.php b/src/Form/IndexFieldsForm.php index e53ecd6..304dfdd 100644 --- a/src/Form/IndexFieldsForm.php +++ b/src/Form/IndexFieldsForm.php @@ -185,6 +185,7 @@ class IndexFieldsForm extends EntityForm { $build['fields'][$key]['indexed'] = array( '#type' => 'checkbox', '#default_value' => $field->isIndexed(), + '#disabled' => $field->isIndexedLocked(), ); $css_key = '#edit-fields-' . Html::getId($key); $build['fields'][$key]['type'] = array( @@ -196,6 +197,7 @@ class IndexFieldsForm extends EntityForm { $css_key . '-indexed' => array('checked' => TRUE), ), ), + '#disabled' => $field->isTypeLocked(), ); $build['fields'][$key]['boost'] = array( '#type' => 'select', @@ -210,7 +212,6 @@ class IndexFieldsForm extends EntityForm { foreach ($fulltext_types as $type) { $build['fields'][$key]['boost']['#states']['visible'][$css_key . '-type'][] = array('value' => $type); } - $build['fields'][$key]['#disabled'] = $field->isLocked(); $build['fields'][$key]['#access'] = !$field->isHidden(); } diff --git a/src/Item/AdditionalField.php b/src/Item/AdditionalField.php index 1e1e84a..e3e8a23 100644 --- a/src/Item/AdditionalField.php +++ b/src/Item/AdditionalField.php @@ -22,6 +22,13 @@ class AdditionalField implements AdditionalFieldInterface { protected $enabled; /** + * Whether this additional field is locked. + * + * @var bool + */ + protected $locked; + + /** * {@inheritdoc} */ public function isEnabled() { @@ -54,13 +61,16 @@ class AdditionalField implements AdditionalFieldInterface { } /** - * Determines whether this additional field's state should be locked. - * - * @return bool - * TRUE if a child of this additional field is enabled or the field was - * nevertheless marked as locked, FALSE otherwise. - * - * @see \Drupal\search_api\Item\GenericFieldInterface::isLocked() + * {@inheritdoc} + */ + public function setLocked($locked = TRUE) { + $this->locked = $locked; + + return $this; + } + + /** + * {@inheritdoc} */ public function isLocked() { if (!isset($this->locked)) { @@ -74,7 +84,6 @@ class AdditionalField implements AdditionalFieldInterface { break; } } - } return $this->locked; } diff --git a/src/Item/AdditionalFieldInterface.php b/src/Item/AdditionalFieldInterface.php index 29041eb..a832d8a 100644 --- a/src/Item/AdditionalFieldInterface.php +++ b/src/Item/AdditionalFieldInterface.php @@ -33,4 +33,23 @@ interface AdditionalFieldInterface extends GenericFieldInterface { */ public function setEnabled($enabled, $notify = FALSE); + /** + * Sets whether this additional field is locked or not. + * + * @param bool $locked + * The new locked state of this additional field. + * + * @return $this + */ + public function setLocked($locked = TRUE); + + /** + * Determines whether this additional field's state should be locked. + * + * @return bool + * TRUE if a child of this additional field is enabled or the field was + * nevertheless marked as locked, FALSE otherwise. + */ + public function isLocked(); + } diff --git a/src/Item/Field.php b/src/Item/Field.php index b961d2b..2e2ce9e 100644 --- a/src/Item/Field.php +++ b/src/Item/Field.php @@ -53,6 +53,20 @@ class Field implements \IteratorAggregate, FieldInterface { protected $boost; /** + * Whether this field should always be enabled/indexed. + * + * @var bool + */ + protected $indexedLocked; + + /** + * Whether this field type should be locked. + * + * @var bool + */ + protected $typeLocked; + + /** * {@inheritdoc} */ public function getType() { @@ -129,7 +143,7 @@ class Field implements \IteratorAggregate, FieldInterface { $fields = $this->index->getOption('fields', array()); $this->indexed = isset($fields[$this->fieldIdentifier]); } - return $this->isLocked() || $this->indexed; + return $this->isIndexedLocked() || $this->indexed; } /** @@ -186,6 +200,60 @@ class Field implements \IteratorAggregate, FieldInterface { } /** + * Determines whether this field should always be enabled/indexed. + * + * @return bool + * TRUE if this field should be locked as enabled/indexed. + * + * @see \Drupal\search_api\Item\GenericFieldInterface::isIndexedLocked() + */ + public function isIndexedLocked() { + return (bool) $this->indexedLocked; + } + + /** + * Sets whether this field should be locked. + * + * @param bool $indexedLocked + * (optional) TRUE if the field should be locked, FALSE otherwise. + * + * @return $this + * + * @see \Drupal\search_api\Item\GenericFieldInterface::setIndexedLocked() + */ + public function setIndexedLocked($indexedLocked = TRUE) { + $this->indexedLocked = $indexedLocked; + return $this; + } + + /** + * Determines whether this type of this field should be locked. + * + * @return bool + * TRUE if type type of this field should be locked. + * + * @see \Drupal\search_api\Item\GenericFieldInterface::isTypeLocked() + */ + public function isTypeLocked() { + return (bool) $this->typeLocked; + } + + /** + * Sets whether type type of this field should be locked. + * + * @param bool $typeLocked + * (optional) TRUE if the field should be locked, FALSE otherwise. + * + * @return $this + * + * @see \Drupal\search_api\Item\GenericFieldInterface::setTypeLocked() + */ + public function setTypeLocked($typeLocked = TRUE) { + $this->typeLocked = $typeLocked; + return $this; + } + + /** * {@inheritdoc} */ public function __sleep() { diff --git a/src/Item/FieldInterface.php b/src/Item/FieldInterface.php index c12c5c2..759073d 100644 --- a/src/Item/FieldInterface.php +++ b/src/Item/FieldInterface.php @@ -130,4 +130,41 @@ interface FieldInterface extends GenericFieldInterface, \Traversable { */ public function setBoost($boost, $notify = FALSE); + /** + * Determines whether this field should always be enabled/indexed. + * + * @return bool + * TRUE if this field should be locked as enabled/indexed. + */ + public function isIndexedLocked(); + + /** + * Sets whether this field should be locked. + * + * @param bool $indexLocked + * (optional) TRUE if the field should be locked, FALSE otherwise. + * + * @return $this + */ + public function setIndexedLocked($indexLocked = TRUE); + + /** + * Determines whether the type of this field should be locked. + * + * @return bool + * TRUE if the type of this field should be locked. + */ + public function isTypeLocked(); + + /** + * Sets whether the type of this field should be locked. + * + * @param bool $typeLocked + * (optional) TRUE if the type of the field should be locked, FALSE + * otherwise. + * + * @return $this + */ + public function setTypeLocked($typeLocked = TRUE); + } diff --git a/src/Item/FieldTrait.php b/src/Item/FieldTrait.php index e7d29dc..42426ec 100644 --- a/src/Item/FieldTrait.php +++ b/src/Item/FieldTrait.php @@ -96,13 +96,6 @@ trait FieldTrait { protected $labelPrefix; /** - * Whether this field should always be enabled/indexed. - * - * @var bool - */ - protected $locked; - - /** * Whether this field should be hidden from the user. * * @var bool @@ -352,33 +345,6 @@ trait FieldTrait { } /** - * Determines whether this field should always be enabled/indexed. - * - * @return bool - * TRUE if this field should be locked as enabled/indexed. - * - * @see \Drupal\search_api\Item\GenericFieldInterface::isLocked() - */ - public function isLocked() { - return (bool) $this->locked; - } - - /** - * Sets whether this field should be locked. - * - * @param bool $locked - * (optional) TRUE if the field should be locked, FALSE otherwise. - * - * @return $this - * - * @see \Drupal\search_api\Item\GenericFieldInterface::setLocked() - */ - public function setLocked($locked = TRUE) { - $this->locked = $locked; - return $this; - } - - /** * Determines whether this field should be hidden from the user. * * @return bool diff --git a/src/Item/GenericFieldInterface.php b/src/Item/GenericFieldInterface.php index cc0872d..96b1fbf 100644 --- a/src/Item/GenericFieldInterface.php +++ b/src/Item/GenericFieldInterface.php @@ -144,24 +144,6 @@ interface GenericFieldInterface { public function setLabelPrefix($label_prefix); /** - * Determines whether this field should always be enabled/indexed. - * - * @return bool - * TRUE if this field should be locked as enabled/indexed. - */ - public function isLocked(); - - /** - * Sets whether this field should be locked. - * - * @param bool $locked - * (optional) TRUE if the field should be locked, FALSE otherwise. - * - * @return $this - */ - public function setLocked($locked = TRUE); - - /** * Determines whether this field should be hidden from the user. * * @return bool diff --git a/src/Plugin/search_api/processor/AddURL.php b/src/Plugin/search_api/processor/AddURL.php index 5f47e16..30587a9 100644 --- a/src/Plugin/search_api/processor/AddURL.php +++ b/src/Plugin/search_api/processor/AddURL.php @@ -35,7 +35,7 @@ class AddURL extends ProcessorPluginBase { 'description' => $this->t('A URI where the item can be accessed'), 'type' => 'uri', ); - $properties['search_api_url'] = BasicProperty::createFromDefinition($definition)->setLocked(); + $properties['search_api_url'] = BasicProperty::createFromDefinition($definition)->setIndexedLocked()->setTypeLocked(); } /** diff --git a/src/Plugin/search_api/processor/AggregatedFields.php b/src/Plugin/search_api/processor/AggregatedFields.php index 16064a0..5bd6cc1 100644 --- a/src/Plugin/search_api/processor/AggregatedFields.php +++ b/src/Plugin/search_api/processor/AggregatedFields.php @@ -388,7 +388,7 @@ class AggregatedFields extends ProcessorPluginBase { 'description' => $this->fieldDescription($field, $index_fields), 'type' => $types[$field['type']], ); - $properties[$field_id] = BasicProperty::createFromDefinition($definition)->setLocked(); + $properties[$field_id] = BasicProperty::createFromDefinition($definition)->setIndexedLocked()->setTypeLocked(); } } } diff --git a/src/Plugin/search_api/processor/ContentAccess.php b/src/Plugin/search_api/processor/ContentAccess.php index 580f1b2..7c24c65 100644 --- a/src/Plugin/search_api/processor/ContentAccess.php +++ b/src/Plugin/search_api/processor/ContentAccess.php @@ -99,9 +99,9 @@ class ContentAccess extends ProcessorPluginBase { if ($datasource) { $entity_type = $datasource->getEntityTypeId(); if (in_array($entity_type, array('node', 'comment'))) { - $properties['status'] = ProxyProperty::create($properties['status'])->setLocked(); + $properties['status'] = ProxyProperty::create($properties['status'])->setIndexedLocked()->setTypeLocked(); if ($entity_type == 'node') { - $properties['uid'] = ProxyProperty::create($properties['uid'])->setLocked(); + $properties['uid'] = ProxyProperty::create($properties['uid'])->setIndexedLocked()->setTypeLocked(); } } return; @@ -112,7 +112,7 @@ class ContentAccess extends ProcessorPluginBase { 'description' => $this->t('Data needed to apply node access.'), 'type' => 'string', ); - $properties['search_api_node_grants'] = BasicProperty::createFromDefinition($definition)->setLocked()->setHidden(); + $properties['search_api_node_grants'] = BasicProperty::createFromDefinition($definition)->setIndexedLocked()->setTypeLocked()->setHidden(); } /** diff --git a/src/Plugin/search_api/processor/Language.php b/src/Plugin/search_api/processor/Language.php index 6a30230..a085b56 100644 --- a/src/Plugin/search_api/processor/Language.php +++ b/src/Plugin/search_api/processor/Language.php @@ -43,7 +43,7 @@ class Language extends ProcessorPluginBase { 'label' => $this->t('Item language'), 'description' => $this->t('The language code of the item'), ); - $properties['search_api_language'] = BasicProperty::createFromDefinition($definition)->setLocked(); + $properties['search_api_language'] = BasicProperty::createFromDefinition($definition)->setIndexedLocked()->setTypeLocked(); } /** diff --git a/src/Plugin/search_api/processor/RenderedItem.php b/src/Plugin/search_api/processor/RenderedItem.php index 213e97c..7bc1190 100644 --- a/src/Plugin/search_api/processor/RenderedItem.php +++ b/src/Plugin/search_api/processor/RenderedItem.php @@ -223,7 +223,7 @@ class RenderedItem extends ProcessorPluginBase { 'label' => $this->t('Rendered HTML output'), 'description' => $this->t('The complete HTML which would be displayed when viewing the item'), ); - $properties['rendered_item'] = BasicProperty::createFromDefinition($definition)->setLocked(); + $properties['rendered_item'] = BasicProperty::createFromDefinition($definition)->setIndexedLocked()->setTypeLocked(); } /** diff --git a/src/Property/PropertyInterface.php b/src/Property/PropertyInterface.php index fd3e1ad..a5fad02 100644 --- a/src/Property/PropertyInterface.php +++ b/src/Property/PropertyInterface.php @@ -15,12 +15,20 @@ use Drupal\Core\TypedData\DataDefinitionInterface; interface PropertyInterface extends DataDefinitionInterface { /** - * Determines whether this processor should always be enabled. + * Determines whether the indexed property should be locked for the processor. * * @return bool - * TRUE if this processor should be forced enabled; FALSE otherwise. + * TRUE if this indexed property should be locked; FALSE otherwise. */ - public function isLocked(); + public function isIndexedLocked(); + + /** + * Determines whether the type property should be locked for the processor. + * + * @return bool + * TRUE if the type should be locked; FALSE otherwise. + */ + public function isTypeLocked(); /** * Determines whether this processor should be hidden from the user. diff --git a/src/Property/PropertyTrait.php b/src/Property/PropertyTrait.php index e05e9c6..12efb6e 100644 --- a/src/Property/PropertyTrait.php +++ b/src/Property/PropertyTrait.php @@ -14,11 +14,18 @@ namespace Drupal\search_api\Property; trait PropertyTrait { /** - * The locked state of the property. + * The locked state of the indexed property. * * @var bool */ - protected $locked = FALSE; + protected $indexedLocked = FALSE; + + /** + * The locked state of the type property. + * + * @var bool + */ + protected $typeLocked = FALSE; /** * The hidden state of the property. @@ -35,28 +42,53 @@ trait PropertyTrait { protected $fieldSettings = array(); /** - * Sets the locked state. + * Sets the indexed locked state for the property. + * + * @param bool $indexedLocked + * (optional) The new indexed locked state for the property. + * + * @return $this + */ + public function setIndexedLocked($indexedLocked = TRUE) { + $this->indexedLocked = $indexedLocked; + return $this; + } + + /** + * Determines whether the indexed property should be locked for the processor. + * + * @return bool + * TRUE if this indexed property should be locked; FALSE otherwise. + * + * @see \Drupal\search_api\Property\PropertyInterface::isIndexLocked() + */ + public function isIndexedLocked() { + return $this->indexedLocked; + } + + /** + * Sets the type locked state for the property. * - * @param bool $locked - * (optional) The new locked state. + * @param bool $typeLocked + * (optional) The new type locked state for the property. * * @return $this */ - public function setLocked($locked = TRUE) { - $this->locked = $locked; + public function setTypeLocked($typeLocked = TRUE) { + $this->typeLocked = $typeLocked; return $this; } /** - * Determines whether this processor should always be enabled. + * Determines whether the type property should be locked for the processor. * * @return bool - * TRUE if this processor should be forced enabled; FALSE otherwise. + * TRUE if the type should be locked; FALSE otherwise. * - * @see \Drupal\search_api\Property\PropertyInterface::isLocked() + * @see \Drupal\search_api\Property\PropertyInterface::isIndexLocked() */ - public function isLocked() { - return $this->locked; + public function isTypeLocked() { + return $this->typeLocked; } /**