public function ParagraphBlocksLabeller::getTitle in Paragraph blocks 8.2
Same name and namespace in other branches
- 3.x src/ParagraphBlocksLabeller.php \Drupal\paragraph_blocks\ParagraphBlocksLabeller::getTitle()
Returns the plugin's paragraph title.
Parameters
string $plugin_id: The plugin id.
bool $enabled: Return if the field is enabled or disabled.
Return value
string The paragraph title.
3 calls to ParagraphBlocksLabeller::getTitle()
- ParagraphBlocksLabeller::hookFormPanelsIpeBlockPluginFormAlter in src/
ParagraphBlocksLabeller.php - Change the title on the add/edit form.
- ParagraphBlocksLabeller::hookLayoutBuilderChooseBlocksAlter in src/
ParagraphBlocksLabeller.php - Removed unused paragraphs and update the layout builder title.
- ParagraphBlocksLabeller::hookPanelsIpeBlocksAlter in src/
ParagraphBlocksLabeller.php - Removes unused paragraphs and update the panels title.
File
- src/
ParagraphBlocksLabeller.php, line 138
Class
- ParagraphBlocksLabeller
- Labels the paragraph blocks once the entity context is known.
Namespace
Drupal\paragraph_blocksCode
public function getTitle($plugin_id, &$enabled) {
$enabled = TRUE;
$plugin_parts = explode(':', $plugin_id);
if (count($plugin_parts) < 4) {
return NULL;
}
list($plugin_type_id, $plugin_entity_type_id, $plugin_field_name, $plugin_field_delta) = $plugin_parts;
if ($plugin_type_id != self::PLUGIN_TYPE_ID) {
return NULL;
}
$plugin_field_bundle = count($plugin_parts) ? $plugin_parts[4] : '';
// Only check the field bundle if it exists. This is new to the 2.x branch.
// So this check exists for backwards compatability with plugins saved
// using the 1.x branch.
if ($plugin_field_bundle) {
// Remove if this paragraph field is not enabled.
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($plugin_entity_type_id, $plugin_field_bundle);
$field_config = $field_definitions[$plugin_field_name]
->getConfig($plugin_field_bundle);
if (!$field_config
->getThirdPartySetting('paragraph_blocks', 'status', TRUE)) {
$enabled = FALSE;
return FALSE;
}
}
// Return if this plugin should be removed from the list.
if (!$this->entity || $this->entity
->bundle() != $plugin_field_bundle || $plugin_field_delta >= $this->entity
->get($plugin_field_name)
->count()) {
return FALSE;
}
// Get the referenced paragraph.
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = $this->entity
->get($plugin_field_name)
->referencedEntities()[$plugin_field_delta];
// Change the label to match admin_label from the referenced paragraph.
return $this
->t('Paragraph: @label', [
'@label' => $paragraph
->getSummary(),
]);
}