class InstallHelper implements ContainerInjectionInterface (View source)

internal  This code is only for use by the Umami demo: Content module.
 

Defines a helper class for importing default content.

Properties

protected AliasManagerInterface $aliasManager

The path alias manager.

protected EntityTypeManagerInterface $entityTypeManager

Entity type manager.

protected ModuleHandlerInterface $moduleHandler

Module handler.

protected StateInterface $state State.
protected FileSystemInterface $fileSystem

The file system.

protected array $enabledLanguages

Enabled languages.

protected array $termIdMap

Term ID map.

protected array $mediaImageIdMap

Media Image CSV ID map.

protected array $nodeIdMap

Node CSV ID map.

Methods

__construct(AliasManagerInterface $aliasManager, EntityTypeManagerInterface $entityTypeManager, ModuleHandlerInterface $moduleHandler, StateInterface $state, FileSystemInterface $fileSystem)

Constructs a new InstallHelper object.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

importContent()

Imports default contents.

$this
getModulePath()

Set module_path variable.

array
readMultilingualContent(string $filename)

Read multilingual content.

int
getTermId(string $vocabulary, int $term_csv_id)

Retrieves the Term ID of a term saved during the import process.

saveTermId(string $vocabulary, int $term_csv_id, int $tid)

Saves a Term ID generated when saving a taxonomy term.

int
getMediaImageId(int $media_image_csv_id)

Retrieves the Media Image ID of a media image saved during the import process.

saveMediaImageId(int $media_image_csv_id, int $media_image_id)

Saves a Media Image ID generated when saving a media image.

string
getNodePath(string $langcode, string $content_type, string $node_csv_id)

Retrieves the node path of node CSV ID saved during the import process.

saveNodePath(string $langcode, string $content_type, string $node_csv_id, string $node_url)

Saves a node CSV ID generated when saving content.

$this
importEditors()

Imports editors.

array
processTerm(array $data, string $vocabulary)

Process terms for a given vocabulary and filename.

array
processImage(array $data)

Process images into media entities.

array
processPage(array $data, string $langcode)

Process pages data into page node structure.

array
processRecipe(array $data, string $langcode)

Process recipe data into recipe node structure.

array
processArticle(array $data, string $langcode)

Process article data into article node structure.

array
processBannerBlock(array $data, string $langcode)

Process block_banner data into block_banner block structure.

array
processDisclaimerBlock(array $data)

Process disclaimer_block data into disclaimer_block block structure.

array
processFooterPromoBlock(array $data, string $langcode)

Process footer_block data into footer_block block structure.

array
processContent(string $bundle_machine_name, array $content, string $langcode)

Process content into a structure that can be saved into Drupal.

$this
importContentFromFile(string $entity_type, string $bundle_machine_name)

Imports content.

$this
deleteImportedContent()

Deletes any content imported by this module.

int
getUser(string $name)

Looks up a user by name, if it is missing the user is created.

int
createFileEntity(string $path)

Creates a file entity based on an image path.

storeCreatedContentUuids(array $uuids)

Stores record of content entities created by this import.

Details

__construct(AliasManagerInterface $aliasManager, EntityTypeManagerInterface $entityTypeManager, ModuleHandlerInterface $moduleHandler, StateInterface $state, FileSystemInterface $fileSystem)

Constructs a new InstallHelper object.

Parameters

AliasManagerInterface $aliasManager

The path alias manager.

EntityTypeManagerInterface $entityTypeManager

Entity type manager.

ModuleHandlerInterface $moduleHandler

Module handler.

StateInterface $state

State service.

FileSystemInterface $fileSystem

The file system.

static create(ContainerInterface $container)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

protected $this getModulePath()

Set module_path variable.

Return Value

$this

protected array readMultilingualContent(string $filename)

Read multilingual content.

Parameters

string $filename

Filename to import.

Return Value

array

An array of two items:

  1. All multilingual content that was read from the files.
  2. List of language codes that need to be imported.

protected int getTermId(string $vocabulary, int $term_csv_id)

Retrieves the Term ID of a term saved during the import process.

Parameters

string $vocabulary

Machine name of vocabulary to which it was saved.

int $term_csv_id

The term's ID from the CSV file.

Return Value

int

Term ID, or 0 if Term ID could not be found.

protected saveTermId(string $vocabulary, int $term_csv_id, int $tid)

Saves a Term ID generated when saving a taxonomy term.

Parameters

string $vocabulary

Machine name of vocabulary to which it was saved.

int $term_csv_id

The term's ID from the CSV file.

int $tid

Term ID generated when saved in the Drupal database.

protected int getMediaImageId(int $media_image_csv_id)

Retrieves the Media Image ID of a media image saved during the import process.

Parameters

int $media_image_csv_id

The media image's ID from the CSV file.

Return Value

int

Media Image ID, or 0 if Media Image ID could not be found.

protected saveMediaImageId(int $media_image_csv_id, int $media_image_id)

Saves a Media Image ID generated when saving a media image.

Parameters

int $media_image_csv_id

The media image's ID from the CSV file.

int $media_image_id

Media Image ID generated when saved in the Drupal database.

protected string getNodePath(string $langcode, string $content_type, string $node_csv_id)

Retrieves the node path of node CSV ID saved during the import process.

Parameters

string $langcode

Current language code.

string $content_type

Current content type.

string $node_csv_id

The node's ID from the CSV file.

Return Value

string

Node path, or 0 if node CSV ID could not be found.

protected saveNodePath(string $langcode, string $content_type, string $node_csv_id, string $node_url)

Saves a node CSV ID generated when saving content.

Parameters

string $langcode

Current language code.

string $content_type

Current content type.

string $node_csv_id

The node's ID from the CSV file.

string $node_url

Node's URL alias when saved in the Drupal database.

protected $this importEditors()

Imports editors.

Other users are created as their content is imported. However, editors don't have their own content so are created here instead.

Return Value

$this

protected array processTerm(array $data, string $vocabulary)

Process terms for a given vocabulary and filename.

Parameters

array $data

Data of line that was read from the file.

string $vocabulary

Machine name of vocabulary to which we should save terms.

Return Value

array

Data structured as a term.

protected array processImage(array $data)

Process images into media entities.

Parameters

array $data

Data of line that was read from the file.

Return Value

array

Data structured as a image.

protected array processPage(array $data, string $langcode)

Process pages data into page node structure.

Parameters

array $data

Data of line that was read from the file.

string $langcode

Current language code.

Return Value

array

Data structured as a page node.

protected array processRecipe(array $data, string $langcode)

Process recipe data into recipe node structure.

Parameters

array $data

Data of line that was read from the file.

string $langcode

Current language code.

Return Value

array

Data structured as a recipe node.

protected array processArticle(array $data, string $langcode)

Process article data into article node structure.

Parameters

array $data

Data of line that was read from the file.

string $langcode

Current language code.

Return Value

array

Data structured as an article node.

protected array processBannerBlock(array $data, string $langcode)

Process block_banner data into block_banner block structure.

Parameters

array $data

Data of line that was read from the file.

string $langcode

Current language code.

Return Value

array

Data structured as a block.

protected array processDisclaimerBlock(array $data)

Process disclaimer_block data into disclaimer_block block structure.

Parameters

array $data

Data of line that was read from the file.

Return Value

array

Data structured as a block.

protected array processFooterPromoBlock(array $data, string $langcode)

Process footer_block data into footer_block block structure.

Parameters

array $data

Data of line that was read from the file.

string $langcode

Current language code.

Return Value

array

Data structured as a block.

protected array processContent(string $bundle_machine_name, array $content, string $langcode)

Process content into a structure that can be saved into Drupal.

Parameters

string $bundle_machine_name

Current bundle's machine name.

array $content

Current content array that needs to be structured.

string $langcode

Current language code.

Return Value

array

Structured content.

protected $this importContentFromFile(string $entity_type, string $bundle_machine_name)

Imports content.

Parameters

string $entity_type

Entity type to be imported

string $bundle_machine_name

Bundle machine name to be imported.

Return Value

$this

$this deleteImportedContent()

Deletes any content imported by this module.

Return Value

$this

protected int getUser(string $name)

Looks up a user by name, if it is missing the user is created.

Parameters

string $name Username.

Return Value

int

User ID.

protected int createFileEntity(string $path)

Creates a file entity based on an image path.

Parameters

string $path

Image path.

Return Value

int

File ID.

protected storeCreatedContentUuids(array $uuids)

Stores record of content entities created by this import.

Parameters

array $uuids

Array of UUIDs where the key is the UUID and the value is the entity type.