Skip to content

Commit

Permalink
Ajout d'un afficheur d'image pour les entitys en one_to_many.
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Aug 6, 2020
1 parent 13d4eb3 commit bdfd0c5
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions core/modules/Node/Form/FormNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,40 @@ public function makeOneToMany($form, $key, $value, $options)
'value' => $idEntity
]);
}
$form->html("$key-$idEntity-delete", '<a:attr>:_content</a>', [
'_content' => '<i class="fa fa-times"></i>',
'class' => 'btn',
'href' => $this->router->getRoute('entity.delete', [

$content = $field[ $options[ 'field_show' ] ];
if ($this->isShowFile($options, $field)) {
$src = $field[ $options[ 'field_type_show' ] ];
$content = "<img src='$src' class='img-thumbnail img-thumbnail-light'/>";
}

$form->html("$key-$idEntity-show", '<a:attr>:_content</a>', [
'_content' => $content,
'href' => $this->router->getRoute('entity.edit', [
':id_node' => $this->content[ 'id' ],
':entity' => $key,
':id_entity' => $field[ "{$key}_id" ]
]),
])
->html("$key-$idEntity-edit", '<a:attr>:_content</a>', [
'_content' => '<i class="fa fa-edit" aria-hidden="true"></i> ' . t('Edit'),
'class' => 'btn',
'href' => $this->router->getRoute('entity.edit', [
':id_node' => $this->content[ 'id' ],
':entity' => $key,
':id_entity' => $field[ "{$key}_id" ]
]),
'_content' => $field[ $options[ 'field_show' ] ]
])
->html("$key-$idEntity-delete", '<a:attr>:_content</a>', [
'_content' => '<i class="fa fa-times" aria-hidden="true"></i> ' . t('Delete'),
'class' => 'btn',
'href' => $this->router->getRoute('entity.delete', [
':id_node' => $this->content[ 'id' ],
':entity' => $key,
':id_entity' => $field[ "{$key}_id" ]
]),
]);
}, [ 'class' => 'sort_weight' ]);
}, [ 'class' => 'sort_weight draggable node-draggable_one_to_many' ]);
}
}, [ 'class' => $options[ 'sort' ] === 'weight'
? 'nested-sortable form-group'
Expand All @@ -278,6 +294,11 @@ public function makeOneToMany($form, $key, $value, $options)
});
}
}

public function isShowFile($options, $field)
{
return isset($options[ 'field_type_show' ]) && $options[ 'field_type_show' ] === 'image' && is_file($field[ $options[ 'field_type_show' ] ]);
}

public function makeRadio(&$form, $key, $value, $options)
{
Expand Down

0 comments on commit bdfd0c5

Please sign in to comment.