Active
Project:
Pipewrench
Version:
1.0.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
24 Feb 2026 at 23:22 UTC
Updated:
4 Mar 2026 at 15:48 UTC
Jump to comment: Most recent
We have a need on several projects for a shared field_short_title field, with a [node:shorter-title] token. It would be nice to have this provided in Pipewrench since it's opinionated and would be good to be available as an API to use in other code instead of having to duplicate it.
/**
* Gets the short title or label for an entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The node entity.
*
* @return string|null
* The short title, or entity label, or NULL neither were avilable.
*/
public static function getEntityShortLabel(EntityInterface $entity): ?string {
return $entity->hasField('field_short_title') && !$entity->get('field_short_title')->isEmpty() ? $entity->get('field_short_title')->getString() : $entity->label();
}
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dave reidComment #4
marcoscanoMy suggestion:
- New submodule:
pipewrench_short_title- The module ships with a new
ShortTitleFieldfield type plugin that extends\Drupal\Core\Field\Plugin\Field\FieldType\StringItemand just overrides the getter and the::isEmpty()to fallback to the entity label if the stored value is empty.- When the module is installed, a new basefield is added to
nodeentities, using our field type- (Possible follow-up): Make it configurable to add the base field to other entities too
- A third-party setting on bundles to make this basefield "active" for that particular bundle. Or maybe we could assume that site-builders would know how to activate it by adjusting form/view displays?
I actually almost think this could make sense in its own project, but I see https://www.drupal.org/project/short_title is taken with a slightly different feature-set, so maybe OK to have it bundled here? 🤷🏼
Comment #5
dave reidYeah, I like the idea of having it as a separate field type, because overriding the getter and isEmpty was making sense to me, it would help simplify the logic and not need a custom token anymore.
Sigh, I wish core had a unified way of adding third party settings to entity bundle config entities, but it doesn't.