在遵循本教程时
http://dirtystylus.com/2018/09/12/graphql-adding-fields-to-types-in-drupal-8/
我正试图在我的应用程序中为GraphQL字段创建一个新的插件。但是,我得到了“无法重新声明类”的致命错误,尽管我很确定在我的应用程序中没有其他地方使用BackgroundImage类。
这是我的dds/src/Plugin/GraphQL/Fields/FieldPluginBase.php文件,其中dds是自定义模块的目录:
namespace Drupal\dds\Plugin\GraphQL\Fields;
use Drupal\graphql\GraphQL\Execution\ResolveContext;
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
use GraphQL\Type\Definition\ResolveInfo;
/**
* A simple field that returns the background image.
*
* For simplicity reasons, this example does not utilize dependency injection.
*
* @GraphQLField(
* id = "backgroundimage",
* type = "String",
* name = "backgroundimage",
* nullable = true,
* multi = false
* )
*/
class BackgroundImage extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
// parent::resolveValues($value, $args, $context, $info);
$fid = \Drupal::config('dds.settings')->get('background_image');
yield $fid;
}
}我得到的错误是:Fatal error: Cannot declare class Drupal\dds\Plugin\GraphQL\Fields\BackgroundImage, because the name is already in use in /app/web/web/modules/custom/dds/src/Plugin/GraphQL/Fields/FieldPluginBase.php on line 33。
发布于 2019-10-29 16:34:04
问题出在文件名上。在将其更改为BackgroundImage.php之后,一切都很好。
https://stackoverflow.com/questions/58421813
复制相似问题