Skip to content

Commit

Permalink
Merge pull request #1 from AsgardCms/3.0
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
ChristianGiupponi committed Aug 29, 2018
2 parents 92dbe20 + 62eeb8c commit 09fcd83
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Modules/Core/macros.php
Expand Up @@ -176,6 +176,32 @@
return new HtmlString($string);
});

Form::macro('i18nFile', function ($name, $title, ViewErrorBag $errors, $lang, $object = null, array $options = []) {
if (array_key_exists('multiple', $options)) {
$nameForm = "{$lang}[$name][]";
} else {
$nameForm = "{$lang}[$name]";
}

$options = array_merge(['class' => 'form-control'], $options);

$string = "<div class='form-group " . ($errors->has($lang . '.' . $name) ? ' has-error' : '') . "'>";
$string .= "<label for='$nameForm'>$title</label>";

if (is_object($object)) {
$currentData = $object->hasTranslation($lang) ? $object->translate($lang)->{$name} : '';
} else {
$currentData = false;
}

$string .= Form::file("{$lang}[{$name}]",$options);

$string .= $errors->first("{$lang}.{$name}", '<span class="help-block">:message</span>');
$string .= '</div>';

return new HtmlString($string);
});

/*
|--------------------------------------------------------------------------
| Standard fields
Expand Down Expand Up @@ -346,6 +372,25 @@
return new HtmlString($string);
});

Form::macro('normalFile', function ($name, $title, ViewErrorBag $errors, $object = null, array $options = []) {
$options = array_merge(['class' => 'form-control', 'placeholder' => $title,'multiple'=>'multiple'], $options);

$string = "<div class='form-group " . ($errors->has($name) ? ' has-error' : '') . "'>";
$string .= Form::label($name, $title);

if (is_object($object)) {
$currentData = $object->{$name} ?: '';
} else {
$currentData = null;
}

$string .= Form::file($name,$options);
$string .= $errors->first($name, '<span class="help-block">:message</span>');
$string .= '</div>';

return new HtmlString($string);
});

Response::macro('csv', function ($file, $filename, $status = 200, $headers = []) {
return response($file, $status, array_merge([
'Content-Type' => 'application/csv',
Expand Down
11 changes: 11 additions & 0 deletions Modules/Page/Entities/Page.php
Expand Up @@ -77,4 +77,15 @@ public function __call($method, $parameters)
#i: No relation found, return the call to parent (Eloquent) to handle it.
return parent::__call($method, $parameters);
}

public function getImageAttribute()
{
$thumbnail = $this->files()->where('zone', 'image')->first();

if ($thumbnail === null) {
return '';
}

return $thumbnail;
}
}

0 comments on commit 09fcd83

Please sign in to comment.