Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arugment #1 is not an Array. TaggableTrait Line 104 #2

Open
F2KLabs opened this issue Jan 29, 2018 · 3 comments
Open

Arugment #1 is not an Array. TaggableTrait Line 104 #2

F2KLabs opened this issue Jan 29, 2018 · 3 comments

Comments

@F2KLabs
Copy link

F2KLabs commented Jan 29, 2018

AsgardCMS Version: 3.5.0
AsgardCMS Blog Module Version: 3.0.1

Situation

Brand new Install of AsgardCMS with asgardcms/blog module installed.

Error

When creating a blog post in the Blog Module, if I do not specify a tag I get an error saying Argument 1 is not an Array from the setTags() method of the TaggableTrait.

screen shot 2018-01-29 at 12 11 57 pm
screen shot 2018-01-29 at 12 12 13 pm
screen shot 2018-01-29 at 2 26 18 pm

  • As a note, the third screenshot was taken at a later time than the other two. As the original did not expand the data array in question. Thus, the data in the two screenshots don't match, but that isn't important to the original issue. Just didn't want someone noticing and trying to deduce why they were different.

Synopsis

There are two array_diff calls in the TaggableTrait's setTags method that expect the first parameter to be an array. In my instance, the EloquentPostRepository makes the setTags call on line 64. That line is expecting a the post data (though this appears to be modified before reaching this method) to contain a 'tags' index. And it does not appear that one is present.

Summary

Hopefully I'm providing enough information. I'm brand new to AsgardCMS. If I've missed a something in setup or am the root of this error, can you provide instruction as to what I did wrong? Thanks.

@Fisiu
Copy link

Fisiu commented Mar 3, 2018

It seems you need to create at least one tag.

It would be nice to have an option to disable tags globally.

@tranfuga25s
Copy link

You can have this modifying the function as follow:

``

/**
 * {@inheritdoc}
 */
public function setTags($tags, $type = 'slug')
{
    if (is_array($tags) && count($tags) > 0) {
        // Get the current entity tags
        $entityTags = $this->tags->pluck($type)->all();

        // Prepare the tags to be added and removed
        $tagsToAdd = array_diff($tags, $entityTags);
        $tagsToDel = array_diff($entityTags, $tags);

        // Detach the tags
        if (count($tagsToDel) > 0) {
            $this->untag($tagsToDel);
        }

        // Attach the tags
        if (count($tagsToAdd) > 0) {
            $this->tag($tagsToAdd);
        }
    }

    return true;
}

``
Haven't check if this breaks anything else... As @F2KLabs I'm new to AsgardCMS code... Should I send a PR for this?

@azamk100
Copy link

Ran into same issue. I used tranfuga's suggestion and it is doing the trick. Would be good to know if that's a supported workaround (i.e. what, if any, are the hidden drawbacks of allowing blank tags?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants