Fixed 'Change resource type' function, err, malfunctioning

Paul B

XenForo moderator
Staff member
Affected version
2.1
There are two issues.

1. If a category has a single resource type, the 'Change resource type' function is still available, but obviously with no choice available:

205333


2. If a category is created with a single resource type of e.g. fileless, a resource is then created, and the category is changed to e.g. uploaded file, the 'Change resource type' function lists both options - the existing resource type and the new type, but selecting the existing type (which is no longer valid), results in an error:

205336
 
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XFRM release (2.1.3).

Change log:
Prevent changing resource types if less than two valid resource types are available.
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Open: src/addons/XFRM/Entity/ResourceItem.php

Find:
PHP:
public function canMove(&$error = null)

Add directly above:
PHP:
    public function canChangeResourceType(&$error = null)
    {
        if (!$this->canReleaseUpdate($error))
        {
            return false;
        }

        $categoryAllowedTypes = 0;

        foreach (['allow_local', 'allow_external', 'allow_commercial_external', 'allow_fileless'] AS $type)
        {
            if (!empty($this->Category[$type]))
            {
                $categoryAllowedTypes++;
            }
        }

        return ($categoryAllowedTypes > 1);
    }

Open: src/addons/XFRM/Pub/Controller/ResourceItem.php

Find:
PHP:
public function actionChangeType(ParameterBag $params)

And below that find the first instance of:
PHP:
if (!$resource->canReleaseUpdate($error))

Replace with:
PHP:
if (!$resource->canChangeResourceType($error))

Open the template: xfrm_resource_wrapper_macros

Find:
Code:
<!--[XF:resource_tools_menu:top]-->

And below that find:
Code:
<xf:if is="$resource.canReleaseUpdate()">

Replace with:
Code:
<xf:if is="$resource.canChangeResourceType()">
 
Top Bottom