public static function renderIgnoreButton($value, array $params, Templater $templater)
{
$params = array_replace([
'entity' => null,
'userKey' => 'user_id',
'contentType' => null
], $params);
if (!($params['entity'] instanceof Entity)) {
throw new \InvalidArgumentException('Invalid entity.');
}
$entity = $params['entity'];
if (!\XF::visitor()->user_id) {
return null;
}
$visitorId = \XF::visitor()->user_id;
if ($params['userKey'] !== null) {
$userId = $entity->getValue($params['userKey']);
if ($userId == $visitorId) {
return null;
}
}
$contentType = self::getContentType($entity, $params);
$contentId = $entity->getEntityId();
if ($contentType === Listener::CONTENT_TYPE_FORUM
&& Listener::isDisabledNode($contentId)
) {
return null;
}
$ignoreLink = \XF::app()
->router('public')
->buildLink(
'misc/ignore-content',
null,
[
'content_type' => $contentType,
'content_id' => $contentId
]
);
$options = [
'href' => $ignoreLink,
'class' => 'menu-linkRow',
'data-xf-click' => $contentType === Listener::CONTENT_TYPE_FORUM ? 'overlay' : 'switch'
];
$ignoreContent = $entity->getRelation('IgnoreContent');
/** @var Ignore|null $ignored */
$ignored = $ignoreContent[$visitorId];
if ($ignored) {
$text = \XF::phrase('ignore_content.unignore');
} else {
$text = \XF::phrase('ignore_content.ignore');
}
return $templater->button($text, $options);
}