Skip to content

Conversation

@brandonkelly
Copy link
Member

Description

Adds a “Copy attribute name” action to all native fields, similar to the “Copy field handle” action on custom fields.

Any native field layout element classes that extend craft\fieldlayoutelements\BaseField directly can include the same action via actionMenuItems() like so:

protected function actionMenuItems(?ElementInterface $element = null, bool $static = false): array
{
    $items = [];

    if (Craft::$app->getUser()->getIsAdmin()) {
        $items[] = $this->copyAttributeAction();
    }

    return $items;
}

copyAttributeAction accepts a $config argument, with the ability to override just about everything:

  • id – the menu item ID
  • icon – the menu item icon (clipboard by default)
  • label – the menu item label (Copy attribute name by default)
  • promptLabel – the copy prompt label (Attribute Name by default)
  • attribute – the value to be copied (whatever attribute() returns by default)

@brandonkelly brandonkelly merged commit 0e01fc1 into 5.9 Dec 1, 2025
@brandonkelly brandonkelly deleted the feature/copy-attribute branch December 1, 2025 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants