@php /** * Media picker library field * * Use with the media library package (HasMedia Trait) * * Use for: * single image * single file (pdf, zip, mp3, etc) * * ToDo: gallery * * Backpack $field parameters: * - name: the name of the field * - label: the label of the field * - hint: the hint of the field * - thumb_slug: the slug of the thumbnail to display (for images) * - allowed_extensions: (defaults to jpg,jpeg,png) Allowed extensions for the file (jpg, pdf, zip, mp3, etc) * */ $selected_values = ( ($crud->entry)? implode(",", $crud->entry->getMedias($field['name'])->pluck('id')->toArray()) : '' ); $find = [ "[", "]", "-" ]; $replace = [ "_", "", "_" ]; $escaped_field_name = str_replace($find, $replace, $field['name']).'_'.rand(10000000, 99999999); //.'_'.str_replace(".","",microtime(true)); @endphp @include('crud::fields.inc.wrapper_start') @php $thumb_slug = null; if(isset($field['thumb_slug'])){ $thumb_slug = ($field['thumb_slug'])? $field['thumb_slug'] : 'small' ; } $allowed_extensions = 'jpg,jpeg,png'; if(isset($field['allowed_extensions'])){ $allowed_extensions = $field['allowed_extensions']; } // dump($crud->entry->getMedias($field['name'])); // dump(( ($crud->entry)? implode(",", $crud->entry->getMedias($field['name'])->pluck('id')->toArray()) : '' )); $media_popup_url = backpack_url('media').'?'.http_build_query([ 'view_type' => 'popup', 'select_mode' => 'single', 'field' => $escaped_field_name, 'id' => (($crud->entry)? $crud->entry->getKey() : null ), 'thumb_slug' => $thumb_slug, 'extensions' => $allowed_extensions ],'', '&'); $value = null; $media = null; if(isset($field['value']) && $field['value']){ $value = $field['value']; $media = getMediaById($field['value']); } if(!$media){ $entry = $crud->entry; if($entry){ $media = $entry->getMedia($field['name']); if($media){ $value = $media->id; }else{ // check if field is in extras column if(isset($entry)){ $extras = json_decode($entry->extras); $repeater_field_name = substr($field['name'], 0, strpos($field['name'], "[")); $find = [ "[", "]" ]; $replace = [ ".", "" ]; $repeater_field_path = str_replace($find, $replace, $field['name']); $obj_extras = (object) $extras; $value = data_get($obj_extras, $repeater_field_path); if($value){ $media = getMediaById($value); } } } } } @endphp @include('crud::fields.inc.translatable_icon')
{!! $field['hint'] !!}
@endif @if(isset($field['allowed_extensions'])){{ __('admin/media_library.form.allowed_extensions') }}: {{ $field['allowed_extensions'] }}
@endif @include('crud::fields.inc.wrapper_end') {{-- ########################################## --}} {{-- Extra CSS and JS for this particular field --}} {{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}} {{-- FIELD CSS - will be loaded in the after_styles section --}} @push('crud_fields_styles') @endpush {{-- FIELD JS - will be loaded in the after_scripts section --}} @push('crud_fields_scripts') @endpush {{-- End of Extra CSS and JS --}} {{-- ########################################## --}}