public function SavedSearch::postCreate in Search API Saved Searches 8
Acts on a created entity before hooks are invoked.
Used after the entity is created, but before saving the entity and before any of the presave hooks are invoked.
See the Entity CRUD topic for more information.
Parameters
\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.
Overrides ContentEntityBase::postCreate
See also
\Drupal\Core\Entity\EntityInterface::create()
File
- src/
Entity/ SavedSearch.php, line 342
Class
- SavedSearch
- Provides an entity type for saved searches.
Namespace
Drupal\search_api_saved_searches\EntityCode
public function postCreate(EntityStorageInterface $storage) {
parent::postCreate($storage);
// The "cachedProperties" values set in preCreate() above will end up in
// $this->value['cachedProperties'] by default. It's probably easiest to
// just let that happen and move the values to the property here.
if (isset($this->values['cachedProperties'])) {
foreach ($this->values['cachedProperties'] as $key => $value) {
$this->cachedProperties[$key] = $value;
}
unset($this->values['cachedProperties']);
}
// Set a default label for new saved searches. (Can't use a "default value
// callback" for the label field because the query only gets set afterwards,
// based on the order of field definitions.)
if (empty($this
->get('label')->value)) {
$label = NULL;
$query = $this
->getQuery();
if ($query && is_string($query
->getOriginalKeys())) {
$label = $query
->getOriginalKeys();
}
$this
->set('label', $label ?: t('Saved search'));
}
}