Skip to content

Use action name as key when adding to headerActions array via Inputfield::addHeaderAction() #568

@Toutouwai

Description

@Toutouwai

When adding a header action to an inputfield via Inputfield::addHeaderAction() the logical place to do this is at renderReady. But this method can be called multiple times (e.g. in Repeater rendering), and therefore duplicates of the action get added.

This would be avoided if it was possible to specify the array key used when the action is added to the array. The action name seems like a good candidate for the key name rather than adding a new setting for the purpose.

Using an array key for header actions would also be useful if header actions become used more widely, as it would then be possible to easily replace the behaviour of a particular action via a hook.

My proposal is to update Inputfield:addHeaderAction() to:

public function addHeaderAction(array $settings = array()) {
	if(!empty($settings['setAll'])) {
		if(is_array($settings['setAll'])) {
			$this->headerActions = array_values($settings['setAll']);
		}
	} else {
		if(isset($settings['name'])) {
			$this->headerActions[$settings['name']] = $settings; // add new action with key
		} else {
			$this->headerActions[] = $settings; // add new action
		}
	}
	return $this->headerActions; // return all
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions