mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 21:13:57 +00:00
Add person alt names in list & view
This commit is contained in:
@@ -22,6 +22,7 @@ namespace Chill\PersonBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
|
||||
/**
|
||||
* Render a Person
|
||||
@@ -29,6 +30,17 @@ use Chill\PersonBundle\Entity\Person;
|
||||
*/
|
||||
class PersonRender extends AbstractChillEntityRender
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ConfigPersonAltNamesHelper
|
||||
*/
|
||||
protected $configAltNamesHelper;
|
||||
|
||||
public function __construct(ConfigPersonAltNamesHelper $configAltNamesHelper)
|
||||
{
|
||||
$this->configAltNamesHelper = $configAltNamesHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Person $person
|
||||
@@ -40,7 +52,8 @@ class PersonRender extends AbstractChillEntityRender
|
||||
return
|
||||
$this->getDefaultOpeningBox('person').
|
||||
'<span class="chill-entity__person__first-name">'.$person->getFirstName().'</span>'.
|
||||
'<span class="chill-entity__person__last-name">'.$person->getLastName().'</span>'.
|
||||
' <span class="chill-entity__person__last-name">'.$person->getLastName().'</span>'.
|
||||
$this->addAltNames($person, true).
|
||||
$this->getDefaultClosingBox()
|
||||
;
|
||||
}
|
||||
@@ -53,7 +66,43 @@ class PersonRender extends AbstractChillEntityRender
|
||||
*/
|
||||
public function renderString($person, array $options): string
|
||||
{
|
||||
return $person->getFirstName().' '.$person->getLastName();
|
||||
return $person->getFirstName().' '.$person->getLastName()
|
||||
.$this->addAltNames($person, false);
|
||||
}
|
||||
|
||||
protected function addAltNames(Person $person, bool $addSpan)
|
||||
{
|
||||
$str = '';
|
||||
|
||||
if ($this->configAltNamesHelper->hasAltNames()) {
|
||||
$altNames = $this->configAltNamesHelper->getChoices();
|
||||
$isFirst = true;
|
||||
|
||||
foreach ($person->getAltNames()->getIterator() as $altName) {
|
||||
/** @var \Chill\PersonBundle\Entity\PersonAltName $altName */
|
||||
if (\array_key_exists($altName->getKey(), $altNames)) {
|
||||
if ($isFirst) {
|
||||
$str .= " (";
|
||||
$isFirst = false;
|
||||
} else {
|
||||
$str.= " ";
|
||||
}
|
||||
if ($addSpan) {
|
||||
$str .= '<span class="chill-entity__person__alt-name chill-entity__person__altname--'.$altName->getKey().'">';
|
||||
}
|
||||
$str .= $altName->getLabel();
|
||||
|
||||
if ($addSpan) {
|
||||
$str .= "</span>";
|
||||
}
|
||||
}
|
||||
if (!$isFirst) {
|
||||
$str .= ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
|
Reference in New Issue
Block a user