You are here

function _smart_title_defaults in Smart Title 8

Helper callback for Smart Title defaults.

@TODO

Parameters

string $entity_type_id: The entity_type_id of the smart title's host entity.

true|null $values_only: Return only the values.

string|null $key: The key of a specific option which default value should be returned. If omitted, every default settings will be returned.

Return value

string[][]|string[]|string An array of smart title default setting values or the value of the specificed option.

3 calls to _smart_title_defaults()
EntityViewDisplayAlterer::addSmartTitle in src/EntityViewDisplayAlterer.php
Adds Smart Title to the entity form.
EntityViewDisplayAlterer::submitSmartTitleForm in src/EntityViewDisplayAlterer.php
Submit callback for saving the smart title configuration.
SmartTitleBuilder::buildView in src/SmartTitleBuilder.php
Applies smart title to an entity build.

File

./smart_title.module, line 224
Contains hooks and private functions of smart_title.module.

Code

function _smart_title_defaults($entity_type_id = 'smart', $values_only = NULL, $key = NULL) {
  $defaults = [
    'smart_title__tag' => [
      'label' => t('HTML tag'),
      'description' => '',
      'default_value' => 'h2',
    ],
    'smart_title__classes' => [
      'label' => t('CSS classes'),
      'description' => '',
      'default_value' => [
        Html::getClass(sprintf('%1$s__title', $entity_type_id)),
      ],
    ],
    'smart_title__link' => [
      'label' => t('Linked to entity'),
      'description' => '',
      'default_value' => TRUE,
    ],
  ];
  if ($values_only) {
    $filter = function ($defaults) {
      return $defaults['default_value'];
    };
    $filtered = array_map($filter, $defaults);
    return $key ? $filtered[$key] : $filtered;
  }
  return $key ? $defaults[$key] : $defaults;
}