Abstract methods error when trying to update a custom module for a custom filter for Craft 4.3.1
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 84
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
Description
When trying to edit a webhook I get the following error:
Class modules\webhookfiltersmodule\filters\UsersChannelFilter contains 9 abstract methods and must therefore be declared abstract or implement the remaining methods (yii\base\StaticInstanceInterface::instance, IteratorAggregate::getIterator, ArrayAccess::offsetExists, ...)
In my learning about this all (bit of a newbie to custom modules) it is my understand that there are some additional methods needed to be declared in order to implement the FilterInterface class.
Wondering if the example in the readme may need to be updated with a better example.
Here is the the code for the filter that is inspiring this error. Like the readme we declare displayName, show, and check. We also declare isSelectable which I am guessing was required for Craft 3.x
Appreciate any guidance so we can get this Craft 4 update complete (and others as we use Webhooks and custom filters on a few sites.
<?php
namespace modules\webhookfiltersmodule\filters;
use craft\elements\User;
use craft\events\UserAssignGroupEvent;
use craft\services\Users;
use craft\webhooks\filters\FilterInterface;
use yii\base\Event;
class UsersChannelFilter implements FilterInterface
{
public static function displayName(): string
{
return 'Only send on confirmation step';
}
public static function isSelectable(): bool
{
return false;
}
public static function show(string $class, string $event): bool
{
return $class === Users::class || $class === User::class;
}
public static function check(Event $event, bool $value): bool
{
/** @var UserAssignGroupEvent|Event $event */
/** @var User $user */
$user = is_a($event, UserAssignGroupEvent::class) ? $event->user : $event->sender;
$user = User::find()->id($user->id)->anyStatus()->one();
$status = $user->getFieldValue('saveOrigin');
if ($status == 'send') {
return true;
}
return false;
}
}
Steps to reproduce
Additional info
- Craft version: 4.3.1
- PHP version: 8.0.24
- Database driver & version:
- Plugins & versions: Webhook 3.0.4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the README example for custom filters and compare it with the Craft 4 FilterInterface requirements described by the error. Update the example so it reflects the required implementation, then verify that the sample no longer produces the reported abstract-method error on Craft 4.3.1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100