public static function Minisite::createInstance in Mini site 8
Create an instance of this class from the field items.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The existing field items.
Return value
\Drupal\minisite\Minisite An instance of this class.
Overrides MinisiteInterface::createInstance
5 calls to Minisite::createInstance()
- MinisiteFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ MinisiteFormatter.php - Builds a renderable array for a field value.
- MinisiteItem::createMinisite in src/
Plugin/ Field/ FieldType/ MinisiteItem.php - Create Minisite instance from field values and save it.
- MinisiteItem::deleteMinisite in src/
Plugin/ Field/ FieldType/ MinisiteItem.php - Delete Minisite instance created from field values.
- minisite_path_insert in ./
minisite.module - Implements hook_path_insert().
- minisite_update_8002 in ./
minisite.install - Re-saves all Minisite instances to populate the database with asset links.
File
- src/
Minisite.php, line 120
Class
- Minisite
- Class Minisite.
Namespace
Drupal\minisiteCode
public static function createInstance(FieldItemListInterface $items) {
$archive_file = $items->entity;
if (!$archive_file) {
return NULL;
}
$field_definition = $items
->getFieldDefinition();
try {
$entity = $items
->getEntity();
$description = '';
$parent_alias = '';
if (!empty($items
->get(0))) {
$description = $items
->get(0)->description;
// Set alias for all assets of this minisite if it was selected for this
// field on this entity and the entity has a path alias set.
$value = $items
->get(0)
->getValue();
$entity_alias = self::getEntityPathAlias($entity);
if (!empty($value['options']['alias_status']) && !empty($entity_alias)) {
$parent_alias = $entity_alias;
}
}
$instance = new self($entity, $field_definition
->getName(), $archive_file, $field_definition
->getSetting('minisite_extensions'));
if (!empty($description)) {
$instance
->setDescription($description);
}
if (!empty($parent_alias)) {
$instance
->setAlias($parent_alias);
}
} catch (ArchiveException $exception) {
$instance = NULL;
}
return $instance;
}