Created
January 18, 2019 15:26
-
-
Save iboved/ff5fe2ed9e3bfa011239a89308818e04 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (GroupSettings::get('extras_module') == 'hotel') { | |
Extra::extend(function ($model) { | |
$model->belongsTo['hotel'] = 'BusyRoomsCMS\Group\Models\Hotel'; | |
$model->rules['hotel'] = 'required'; | |
$model->attributeNames['hotel'] = 'busyroomscms.group::lang.hotels.labels.hotel'; | |
}); | |
Extras::extendListColumns(function ($list, $model) { | |
if (!$list->model instanceof Extra) { | |
return; | |
} | |
foreach ($list->getColumns() as $key => $column) { | |
$list->removeColumn($key); | |
} | |
$hotelColumn = [ | |
'hotel' => [ | |
'label' => 'busyroomscms.group::lang.hotels.labels.hotel', | |
'relation' => 'hotel', | |
'select' => 'hotel_name', | |
], | |
]; | |
$list->addColumns($hotelColumn + $list->columns); | |
}); | |
Extras::extendListFilterScopes(function ($filter) { | |
$filter->addScopes([ | |
'hotel' => [ | |
'label' => 'busyroomscms.group::lang.hotels.labels.hotel', | |
'modelClass' => 'BusyRoomsCMS\Group\Models\Hotel', | |
'conditions' => 'hotel_id in (:filtered)', | |
'nameFrom' => 'hotel_name', | |
] | |
]); | |
}); | |
Event::listen('backend.form.extendFieldsBefore', function ($widget) { | |
if (!$widget->getController() instanceof Extras) { | |
return; | |
} | |
if (!$widget->model instanceof Extra) { | |
return; | |
} | |
if ($widget->isNested) { | |
return; | |
} | |
$hotelField = [ | |
'hotel' => [ | |
'label' => 'busyroomscms.group::lang.hotels.labels.hotel', | |
'type' => 'relation', | |
'nameFrom' => 'hotel_name', | |
'placeholder' => 'busyroomscms.group::lang.hints.not_selected', | |
'span' => 'right', | |
'tab' => 'busyroomscms.content::lang.extras.tabs.basic', | |
], | |
]; | |
// Add "hotel" field to the second position | |
$oldFields = array_get($widget->tabs, 'fields', []); | |
$newFields = array_slice($oldFields, 0, 1) + $hotelField + array_slice($oldFields, 1); | |
$widget->tabs['fields'] = $newFields; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment