Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions modules/backend/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php namespace Backend;

use App;
use Backend;
use BackendMenu;
use BackendAuth;
Expand All @@ -23,12 +22,15 @@ public function register()
$this->registerConsole();
$this->registerMailer();
$this->registerAssetBundles();
$this->registerBackendPermissions();

if (!$this->app->runningUnitTests()) {
$this->registerBackendPermissions();
}

/*
* Backend specific
*/
if (App::runningInBackend()) {
if ($this->app->runningInBackend()) {
$this->registerBackendNavigation();
$this->registerBackendReportWidgets();
$this->registerBackendWidgets();
Expand Down
2 changes: 1 addition & 1 deletion modules/backend/behaviors/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function initForm($model, $context = null)
* Detected Relation controller behavior
*/
if ($this->controller->isClassExtendedWith(\Backend\Behaviors\RelationController::class)) {
$this->controller->initRelation($model);
$this->controller->initRelation(clone $model);
}

$this->prepareVars($model);
Expand Down
45 changes: 20 additions & 25 deletions modules/backend/formwidgets/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,16 @@ protected function getFileRecord()
$record = false;

if (!empty(post('file_id'))) {
$record = $this->getRelationModel()::find(post('file_id')) ?: false;
$record = $this->getRelationModel()->find(post('file_id')) ?: false;
}

return $record;
}

/**
* Get the instantiated config Form widget
*
* @return void
*/
public function getConfigFormWidget()
public function getConfigFormWidget(): Form
{
if ($this->configFormWidget) {
return $this->configFormWidget;
Expand Down Expand Up @@ -222,9 +220,8 @@ protected function getFileList()

/**
* Returns the display mode for the file upload. Eg: file-multi, image-single, etc.
* @return string
*/
protected function getDisplayMode()
protected function getDisplayMode(): string
{
$mode = $this->getConfig('mode', 'image');

Expand All @@ -233,16 +230,15 @@ protected function getDisplayMode()
}

$relationType = $this->getRelationType();
$mode .= ($relationType == 'attachMany' || $relationType == 'morphMany') ? '-multi' : '-single';
$mode .= ($relationType === 'attachMany' || $relationType === 'morphMany') ? '-multi' : '-single';

return $mode;
}

/**
* Returns the escaped and translated prompt text to display according to the type.
* @return string
*/
protected function getPromptText()
protected function getPromptText(): string
{
if ($this->prompt === null) {
$isMulti = ends_with($this->getDisplayMode(), 'multi');
Expand All @@ -257,10 +253,8 @@ protected function getPromptText()
/**
* Returns the CSS dimensions for the uploaded image,
* uses auto where no dimension is provided.
* @param string $mode
* @return string
*/
protected function getCssDimensions($mode = null)
protected function getCssDimensions(?string $mode = null): string
{
if (!$this->imageWidth && !$this->imageHeight) {
return '';
Expand All @@ -270,20 +264,19 @@ protected function getCssDimensions($mode = null)

if ($mode == 'block') {
$cssDimensions .= $this->imageWidth
? 'width: '.$this->imageWidth.'px;'
: 'width: '.$this->imageHeight.'px;';
? 'width: ' . $this->imageWidth . 'px;'
: 'width: ' . $this->imageHeight . 'px;';

$cssDimensions .= ($this->imageHeight)
? 'max-height: '.$this->imageHeight.'px;'
? 'max-height: ' . $this->imageHeight . 'px;'
: 'height: auto;';
}
else {
} else {
$cssDimensions .= $this->imageWidth
? 'width: '.$this->imageWidth.'px;'
? 'width: ' . $this->imageWidth . 'px;'
: 'width: auto;';

$cssDimensions .= ($this->imageHeight)
? 'max-height: '.$this->imageHeight.'px;'
? 'max-height: ' . $this->imageHeight . 'px;'
: 'height: auto;';
}

Expand Down Expand Up @@ -333,18 +326,19 @@ public function getAcceptedFileTypes($includeDot = false)
/**
* Removes a file attachment.
*/
public function onRemoveAttachment()
public function onRemoveAttachment(): void
{
$fileModel = $this->getRelationModel();
if (($fileId = post('file_id')) && ($file = $fileModel::find($fileId))) {
if ($file = $this->getFileRecord()) {
$this->getRelationObject()->remove($file, $this->sessionKey);
}
}

/**
* Sorts file attachments.
*
* Expects (array) sortOrder [$fileId => $fileOrder] in the POST data.
*/
public function onSortAttachments()
public function onSortAttachments(): void
{
if ($sortData = post('sortOrder')) {
$ids = array_keys($sortData);
Expand All @@ -357,10 +351,11 @@ public function onSortAttachments()

/**
* Loads the configuration form for an attachment, allowing title and description to be set.
*
* @throws ApplicationException if unable to find the file record
*/
public function onLoadAttachmentConfig()
public function onLoadAttachmentConfig(): string
{
$fileModel = $this->getRelationModel();
if ($file = $this->getFileRecord()) {
$file = $this->decorateFileAttributes($file);

Expand Down
5 changes: 2 additions & 3 deletions modules/backend/formwidgets/RecordFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Lang;
use ApplicationException;
use Backend\Classes\FormWidgetBase;
use Winter\Storm\Database\Model;

/**
* Record Finder
Expand Down Expand Up @@ -312,10 +313,8 @@ public function onFindRecord()

/**
* Gets the base model instance used by this field
*
* @return \Winter\Storm\Database\Model
*/
protected function getRecordModel()
protected function getRecordModel(): Model
{
$model = null;
if ($this->useRelation) {
Expand Down
3 changes: 1 addition & 2 deletions modules/backend/formwidgets/TagList.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ public function getSaveValue($value)
/**
* Returns an array suitable for saving against a relation (array of keys).
* This method also creates non-existent tags.
* @return array
*/
protected function hydrateRelationSaveValue($names)
protected function hydrateRelationSaveValue($names): array
{
if (!$names) {
return $names;
Expand Down
32 changes: 13 additions & 19 deletions modules/backend/traits/FormModelWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use Lang;
use ApplicationException;
use Exception;
use Winter\Storm\Database\Model;
use Winter\Storm\Database\Relations\Relation;

/**
* Form Model Widget Trait
Expand All @@ -12,18 +14,14 @@
* @package winter\wn-backend-module
* @author Alexey Bobkov, Samuel Georges
*/

trait FormModelWidget
{

/**
* Returns the final model and attribute name of
* a nested HTML array attribute.
* Returns the final model and attribute name of a nested HTML array attribute.
* Eg: list($model, $attribute) = $this->resolveModelAttribute($this->valueFrom);
* @param string $attribute.
* @return array
* @throws ApplicationException if something goes wrong when attempting to resolve the model attribute
*/
public function resolveModelAttribute($attribute)
public function resolveModelAttribute(string $attribute): array
{
try {
return $this->formField->resolveModelAttribute($this->model, $attribute);
Expand All @@ -37,11 +35,10 @@ public function resolveModelAttribute($attribute)
}

/**
* Returns the model of a relation type,
* supports nesting via HTML array.
* @return Relation
* Returns the model of a relation type, supports nesting via HTML array.
* @throws ApplicationException if the related model cannot be resolved
*/
public function getRelationModel()
public function getRelationModel(): Model
{
list($model, $attribute) = $this->resolveModelAttribute($this->valueFrom);

Expand All @@ -63,11 +60,10 @@ public function getRelationModel()
}

/**
* Returns the value as a relation object from the model,
* supports nesting via HTML array.
* @return Relation
* Returns the value as a relation object from the model, supports nesting via HTML array.
* @throws ApplicationException if the relationship cannot be resolved
*/
protected function getRelationObject()
protected function getRelationObject(): Relation
{
list($model, $attribute) = $this->resolveModelAttribute($this->valueFrom);

Expand All @@ -89,11 +85,9 @@ protected function getRelationObject()
}

/**
* Returns the value as a relation type from the model,
* supports nesting via HTML array.
* @return Relation
* Returns the value as a relation type from the model, supports nesting via HTML array.
*/
protected function getRelationType()
protected function getRelationType(): ?string
{
list($model, $attribute) = $this->resolveModelAttribute($this->valueFrom);
return $model->getRelationType($attribute);
Expand Down
3 changes: 1 addition & 2 deletions modules/backend/widgets/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -1802,11 +1802,10 @@ public function onToggleTreeNode()

/**
* Check if column refers to a relation of the model
* @param ListColumn $column List column object
* @param boolean $multi If set, returns true only if the relation is a "multiple relation type"
* @return boolean
*/
protected function isColumnRelated($column, $multi = false)
protected function isColumnRelated(ListColumn $column, bool $multi = false): bool
{
if (!isset($column->relation) || $this->isColumnPivot($column)) {
return false;
Expand Down
47 changes: 24 additions & 23 deletions modules/cms/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
<?php namespace Cms;

use App;
use Url;
use Lang;
use File;
use Event;
use Config;
use Backend;
use BackendMenu;
use Backend\Classes\WidgetManager;
use Backend\Models\UserRole;
use BackendAuth;
use Cms\Models\ThemeLog;
use Cms\Models\ThemeData;
use BackendMenu;
use Cms\Classes\CmsObject;
use Backend\Models\UserRole;
use Cms\Classes\Page as CmsPage;
use Cms\Classes\ComponentManager;
use Cms\Classes\Page as CmsPage;
use Cms\Classes\Theme;
use Cms\Models\ThemeData;
use Cms\Models\ThemeLog;
use Cms\Twig\DebugExtension;
use Cms\Twig\Extension as CmsTwigExtension;
use Cms\Twig\Loader as CmsTwigLoader;
use Config;
use Event;
use File;
use Lang;
use System\Classes\CombineAssets;
use Cms\Classes\Theme as CmsTheme;
use Backend\Classes\WidgetManager;
use System\Classes\MarkupManager;
use System\Classes\SettingsManager;
use Twig\Cache\FilesystemCache as TwigCacheFilesystem;
use Cms\Twig\Loader as CmsTwigLoader;
use Cms\Twig\DebugExtension;
use Cms\Twig\Extension as CmsTwigExtension;

use Url;
use Winter\Storm\Support\ModuleServiceProvider;

class ServiceProvider extends ModuleServiceProvider
Expand All @@ -43,12 +41,15 @@ public function register()
$this->registerThemeLogging();
$this->registerCombinerEvents();
$this->registerHalcyonModels();
$this->registerBackendPermissions();

if (!$this->app->runningUnitTests()) {
$this->registerBackendPermissions();
}

/*
* Backend specific
*/
if (App::runningInBackend()) {
if ($this->app->runningInBackend()) {
$this->registerBackendNavigation();
$this->registerBackendReportWidgets();
$this->registerBackendWidgets();
Expand All @@ -68,7 +69,7 @@ public function boot()
$this->bootMenuItemEvents();
$this->bootRichEditorEvents();

if (App::runningInBackend()) {
if ($this->app->runningInBackend()) {
$this->bootBackendLocalization();
}
}
Expand All @@ -94,7 +95,7 @@ protected function registerConsole()
protected function registerTwigParser()
{
// Register CMS Twig environment
App::bind('twig.environment.cms', function ($app) {
$this->app->bind('twig.environment.cms', function ($app) {
// Load Twig options
$useCache = !Config::get('cms.twigNoCache');
$isDebugMode = Config::get('app.debug', false);
Expand Down Expand Up @@ -163,7 +164,7 @@ protected function registerThemeLogging()
*/
protected function registerCombinerEvents()
{
if (App::runningInBackend() || App::runningInConsole()) {
if ($this->app->runningInBackend() || $this->app->runningInConsole()) {
return;
}

Expand Down Expand Up @@ -386,7 +387,7 @@ protected function registerBackendSettings()
*/
protected function bootBackendLocalization()
{
$theme = CmsTheme::getActiveTheme();
$theme = Theme::getActiveTheme();

if (is_null($theme)) {
return;
Expand Down
Loading