protected function EntityconnectWidgetProcessor::attachEditButton in Entity connect 8.2
Attach the edit button.
Parameters
array $element: The widget container element.
string[] $entityconnect_classes: Button CSS definition array:
- 'extra_class': extra css class string
- 'parents_class': parents class string.
int|string $key: Target entity id (optional).
1 call to EntityconnectWidgetProcessor::attachEditButton()
- EntityconnectWidgetProcessor::attachButtons in src/
EntityconnectWidgetProcessor.php - Attach the entity connect buttons to a single widget element.
File
- src/
EntityconnectWidgetProcessor.php, line 287
Class
- EntityconnectWidgetProcessor
- A reference field widget processing class for entityconnect module.
Namespace
Drupal\entityconnectCode
protected function attachEditButton(array &$element, array $entityconnect_classes, $key = 'all') {
// Button values are opposite; 0=On, 1=Off.
$editbuttonallowed = empty($this->entityconnectSettings['buttons']['button_edit']);
$editIcon = $this->entityconnectSettings['icons']['icon_edit'];
// Now we need to make sure the user should see this button.
if (\Drupal::currentUser()
->hasPermission('entityconnect edit button') && $editbuttonallowed) {
$classes = [];
// Determine how the button should be displayed.
if (isset($editIcon)) {
if ($editIcon == '0') {
$classes = $entityconnect_classes['extra_class'] . ' edit-icon';
}
elseif ($editIcon == '1') {
$classes = $entityconnect_classes['extra_class'] . ' edit-icon edit-text';
}
else {
$classes = $entityconnect_classes['extra_class'];
}
}
// Build the button name.
$button_name = "edit_entityconnect__{$this->fieldDefinition->getName()}_{$key}_{$entityconnect_classes['parents_class']}";
// Build the button element.
$element[$button_name] = [
'#type' => 'entityconnect_submit',
'#value' => $this
->t('Edit content'),
'#name' => $button_name,
'#prefix' => "<div class = 'entityconnect-edit {$classes}'>",
'#suffix' => '</div>',
'#key' => $key,
'#field' => $this->fieldDefinition
->getName(),
'#entity_type_target' => $this->entityType,
'#acceptable_types' => $this->acceptableTypes,
'#add_child' => FALSE,
'#weight' => 1,
];
// Button should be at same form level as widget,
// or text box if multivalue autocomplete field.
$parents = $this->widget['#parents'];
if (is_numeric($key)) {
$parents[] = $key;
}
$element[$button_name]['#parents'] = array_merge($parents, [
$button_name,
]);
}
}