В параграфе есть множественное поле ссылки на тип материала "сотрудник". Из выпадающего списка выбираю несколько сотрудников и далее переопределяю обёртку в шаблоне параграфа.
Вопрос - как мне корректно получить значения нужных полей? Мой код:
<?php
$employee = field_get_items('paragraphs_item', $variables['paragraphs_item'], 'field_employee');
?>
<?php if(!empty($employee)){ ?>
<section class="container big-mn-bottom"<?php print $attributes; ?>>
<div class="FellowWorkerCardsList">
<ul class="FellowWorkerCardsList__list">
<?php
foreach ($employee as $key => $value) {
$employee_title = $employee[$key]['title'];
$employee_url = $employee[$key]['url'];
$employee_avatar = $employee[$key]['field_worker_photo'];
$employee_phone = $employee[$key]['field_worker_phone'];
$employee_email = $employee[$key]['field_worker_email'];
$employee_post = $employee[$key]['field_worker_post'];
?>
<li class="FellowWorkerCardsList__list__item">
<div class="FellowWorkerCard">
<div class="FellowWorkerCard__content">
<div class="FellowWorkerCard__content__imgContainer">
<div class="FellowWorkerCard__content__imgContainer__img" style="background-image: url(<?php print $employee_avatar; ?>)"></div>
</div>
<div class="FellowWorkerCard__content__dscrContainer">
<h3 class="FellowWorkerCard__content__dscrContainer__name"><?php print $employee_title; ?></h3>
<?php if (!empty($employee_post)): ?>
<span class="FellowWorkerCard__content__dscrContainer__position"><?php print $employee_post; ?></span>
<?php endif ?>
<?php if (!empty($employee_phone)): ?>
<span class="FellowWorkerCard__content__dscrContainer__tel"><?php print $employee_phone; ?></span>
<?php endif ?>
<?php if (!empty($employee_email)): ?>
<a class="FellowWorkerCard__content__dscrContainer__mail" href="mailto:<?php print $employee_email; ?>"><?php print $employee_email; ?></a>
<?php endif ?>
</div>
</div>
</div>
</li>
<?php
}
?>
</ul>
</div>
</section>
<?php
}
?>
Не получается достать именно значения. Как понял field_get_items должен их содержать
Комментарии
Или как вывести тизер этой ноды или любой другой режим просмотра?
viewfield не?
Разобрался, ответ выглядит так:
<?php
foreach ($employee as $key => $value) {
$employee_title = $employee[$key]['entity']->title;
$employee_avatar_uri = $employee[$key]['entity']->field_worker_photo['und'][0]['uri'];
$employee_phone = $employee[$key]['entity']->field_worker_phone['und'][0]['value'];
$employee_email = $employee[$key]['entity']->field_worker_email['und'][0]['email'];
$employee_post = $employee[$key]['entity']->field_worker_post['und'][0]['tid'];
?>
Два момента:
Мой итоговый код полностью:
<?php
$employee = field_get_items('paragraphs_item', $variables['paragraphs_item'], 'field_employee');
?>
<?php if(!empty($employee)){ ?>
<section class="container big-mn-bottom"<?php print $attributes; ?>>
<div class="FellowWorkerCardsList">
<ul class="FellowWorkerCardsList__list">
<?php
foreach ($employee as $key => $value) {
$employee_title = $employee[$key]['entity']->title;
$employee_avatar_uri = $employee[$key]['entity']->field_worker_photo['und'][0]['uri'];
$employee_phone = $employee[$key]['entity']->field_worker_phone['und'][0]['value'];
$employee_email = $employee[$key]['entity']->field_worker_email['und'][0]['email'];
$employee_post_term = taxonomy_term_load($employee[$key]['entity']->field_worker_post['und'][0]['tid']);
$employee_post_name = $employee_post_term->name;
?>
<li class="FellowWorkerCardsList__list__item">
<div class="FellowWorkerCard">
<div class="FellowWorkerCard__content">
<div class="FellowWorkerCard__content__imgContainer">
<?php print '<div class="FellowWorkerCard__content__imgContainer__img" style="background-image: url('.file_create_url($employee_avatar_uri).')"></div>'; ?>
</div>
<div class="FellowWorkerCard__content__dscrContainer">
<h3 class="FellowWorkerCard__content__dscrContainer__name"><?php print $employee_title; ?></h3>
<?php if (!empty($employee_post_term)): ?>
<span class="FellowWorkerCard__content__dscrContainer__position"><?php print $employee_post_name; ?></span>
<?php endif ?>
<?php if (!empty($employee_phone)): ?>
<span class="FellowWorkerCard__content__dscrContainer__tel"><?php print $employee_phone; ?></span>
<?php endif ?>
<?php if (!empty($employee_email)): ?>
<a class="FellowWorkerCard__content__dscrContainer__mail" href="mailto:<?php print $employee_email; ?>"><?php print $employee_email; ?></a>
<?php endif ?>
</div>
</div>
</div>
</li>
<?php
}
?>
</ul>
</div>
</section>
<?php
}
?>