bobdenotter/seo

[bug] - Field type

nlemoine opened this issue · 9 comments

While working on a bundle that imports content in a nut command, i stumbled upon a strange issue.

I used $app['storage']->getEmptyContent('pages') and got this error:

Type error: Argument 2 passed to Doctrine\DBAL\Types\TextType::convertToPHPValue() must be an instance of Doctrine\DBAL\Platforms\AbstractPlatform, null given, called in /path/to/vendor/bolt/bolt/src/Storage/Field/Type/FieldTypeBase.php on line 123

A couple of tests later, I figured Bolt SEO was responsible for this.

Looks like extending FieldTypeBase to create a new field is causing the issue. Implementing the FieldInterface like mentioned seems to resolved the problem.

You can check the PR I submitted.

Sorry, forgot to mention some details:

  • Bolt 3.3.3
  • PHP 7.1.6

Closed by #53

@nlemoine that method is a legacy one, and shouldn't be used in PHP.

If you need a new ContentType record you can either do similar to :

        $repo = $app['storage']->getRepository('pages');
        $entity = new \Bolt\Storage\Entity\Content([
            'title' => 'Koala',
            'slug'  => 'koala',
        ]);
        $repo->save($entity);

All the documentation is https://docs.bolt.cm/3.3/extensions/storage/introduction

@GawainLynch Thanks! I got this snippet from this gist.

Is setValues() still a valid method to set entity content?

No, but you can use one of two (well more, but run with either of these), assuming the database field is called koala you can:

$entity->set('koala', $value);

// or 
$entity->setKoala($value);

So this method will be deprecated?

Looks like a simple shortcut to avoid a loop on a array of fields/values.

$values = [
    'title' => 'Koala',
    'slug' => 'koala,
];
foreach ($values as $k => $v) {
    $entity->set($k , $v);
}

Excuse me for a minute … I just need to go and sit in the Stupid Corner! I'll be right back 🤣

Yep, sorry I thought you were referring to the old legacy Content object method … I need my brain checked 🤣

😄 No problem