backports murph-skeleton
This commit is contained in:
parent
761d697363
commit
6f2a9e9c7b
|
@ -40,8 +40,8 @@ abstract class Field
|
|||
$resolver->setAllowedTypes('property', ['null', 'string']);
|
||||
$resolver->setAllowedTypes('view', 'string');
|
||||
$resolver->setAllowedTypes('attr', 'array');
|
||||
$resolver->setAllowedTypes('href', ['null', 'string']);
|
||||
$resolver->setAllowedTypes('href_attr', 'array');
|
||||
$resolver->setAllowedTypes('href', ['null', 'string', 'callable']);
|
||||
$resolver->setAllowedTypes('href_attr', 'array', 'callable');
|
||||
$resolver->setAllowedTypes('raw', 'boolean');
|
||||
$resolver->setAllowedTypes('property_builder', ['null', 'callable']);
|
||||
$resolver->setAllowedValues('sort', function($value) {
|
||||
|
|
|
@ -42,14 +42,27 @@ class CrudExtension extends AbstractExtension
|
|||
$render = $instance->buildView($this->twig, $entity, $resolver->resolve($config['options']), $locale);
|
||||
|
||||
if (isset($config['options']['href'])) {
|
||||
$config['options']['href_attr'] = $config['options']['href_attr'] ?? [];
|
||||
$hrefAttrConfig = $config['options']['href_attr'] ?? [];
|
||||
$hrefConfig = $config['options']['href'] ?? null;
|
||||
$attributes = '';
|
||||
|
||||
foreach ($config['options']['href_attr'] as $k => $v) {
|
||||
if (is_callable($hrefAttrConfig)) {
|
||||
$attrs = (array) call_user_func($hrefAttrConfig, $entity, $config['options']);
|
||||
} else {
|
||||
$attrs = $hrefAttrConfig;
|
||||
}
|
||||
|
||||
if (is_callable($hrefConfig)) {
|
||||
$href = call_user_func($hrefConfig, $entity, $config['options']);
|
||||
} else {
|
||||
$href = $hrefConfig;
|
||||
}
|
||||
|
||||
foreach ($attrs as $k => $v) {
|
||||
$attributes .= sprintf('%s="%s" ', htmlspecialchars($k), htmlspecialchars($v));
|
||||
}
|
||||
|
||||
$render = sprintf('<a href="%s" %s>%s</a>', htmlspecialchars($config['options']['href']), $attributes, $render);
|
||||
$render = sprintf('<a href="%s" %s>%s</a>', htmlspecialchars($href), $attributes, $render);
|
||||
}
|
||||
|
||||
return $render;
|
||||
|
|
Loading…
Reference in a new issue