首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Drupal GraphQL插件中重新声明类

无法在Drupal GraphQL插件中重新声明类
EN

Stack Overflow用户
提问于 2019-10-16 21:15:00
回答 1查看 101关注 0票数 1

在遵循本教程时

http://dirtystylus.com/2018/09/12/graphql-adding-fields-to-types-in-drupal-8/

我正试图在我的应用程序中为GraphQL字段创建一个新的插件。但是,我得到了“无法重新声明类”的致命错误,尽管我很确定在我的应用程序中没有其他地方使用BackgroundImage类。

这是我的dds/src/Plugin/GraphQL/Fields/FieldPluginBase.php文件,其中dds是自定义模块的目录:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2019-10-29 16:34:04

问题出在文件名上。在将其更改为BackgroundImage.php之后,一切都很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58421813

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档