From 1adf6232baf5b6567b72a2a537777bc41dc7674a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 10 May 2023 19:43:22 +0200 Subject: [PATCH] wait #5928 @0.25 --- src/app/Magic/Fields/Field.php | 4 +-- .../views/columns/textwrap.blade.php | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/resources/views/columns/textwrap.blade.php diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index 7e93288..8f9837a 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -148,7 +148,7 @@ class Field implements \ArrayAccess 'filter' => false, 'filter_type' => $this->_filterType, 'filter_label' => null, 'filter_values' => $this->_filterValues, 'translatable' => $this->_translatable, 'migrateTranslatable' => $this->_migrateTranslatable, 'preview' => $this->_preview, - 'column_type' => $this->_columnType, 'column_move_after' => $this->_columnMoveAfter, 'column_format' => $this->_columnFormat, 'column_width' => 300, 'column_escape' => true, + 'column_type' => $this->_columnType, 'column_move_after' => $this->_columnMoveAfter, 'column_format' => $this->_columnFormat, 'column_width' => 300, 'column_escape' => true, 'column_limit' => 50, 'default' => $this->_default, 'non_default_tracking' => true, 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic, 'allow_null' => true, @@ -263,6 +263,7 @@ class Field implements \ArrayAccess 'format' => $this->getAttribute('column_format', null), 'orderable' => true, 'escaped' => $this->getAttribute('column_escape', true), + 'limit' => $this->getAttribute('column_limit', 50), ]; if ($this->hasAttribute('column_function_name')) { @@ -273,7 +274,6 @@ class Field implements \ArrayAccess $res['limit'] = $this->getAttribute('column_limit'); } - return $res; } diff --git a/src/resources/views/columns/textwrap.blade.php b/src/resources/views/columns/textwrap.blade.php new file mode 100644 index 0000000..ccd4f7d --- /dev/null +++ b/src/resources/views/columns/textwrap.blade.php @@ -0,0 +1,31 @@ +{{-- regular object attribute --}} +@php + $column['value'] = $column['value'] ?? data_get($entry, $column['name']); + $column['escaped'] = $column['escaped'] ?? true; + $column['limit'] = $column['limit'] ?? 32; + $column['prefix'] = $column['prefix'] ?? ''; + $column['suffix'] = $column['suffix'] ?? ''; + $column['text'] = $column['default'] ?? '-'; + + if($column['value'] instanceof \Closure) { + $column['value'] = $column['value']($entry); + } + + if(is_array($column['value'])) { + $column['value'] = json_encode($column['value']); + } + + if(!empty($column['value'])) { + $column['text'] = $column['prefix'].Str::limit($column['value'], $column['limit'], '…').$column['suffix']; + } +@endphp + + + @includeWhen(!empty($column['wrapper']), 'crud::columns.inc.wrapper_start') + @if($column['escaped']) + {{ $column['text'] }} + @else + {!! $column['text'] !!} + @endif + @includeWhen(!empty($column['wrapper']), 'crud::columns.inc.wrapper_end') + -- 2.39.5