diff --git a/src/Plugin/Deriver/Fields/ViewDeriver.php b/src/Plugin/Deriver/Fields/ViewDeriver.php index cb65606..be12203 100644 --- a/src/Plugin/Deriver/Fields/ViewDeriver.php +++ b/src/Plugin/Deriver/Fields/ViewDeriver.php @@ -56,143 +56,4 @@ public function getDerivativeDefinitions($basePluginDefinition) { return parent::getDerivativeDefinitions($basePluginDefinition); } - /** - * Helper function to return the contextual filter argument if any exist. - * - * @param array $arguments - * The array of available arguments. - * @param $id - * The plugin derivative id. - * - * @return array - * The contextual filter argument if applicable. - */ - protected function getContextualArguments(array $arguments, $id) { - if (!empty($arguments)) { - return [ - 'contextualFilter' => [ - 'type' => StringHelper::camelCase($id, 'contextual', 'filter', 'input'), - ], - ]; - } - - return []; - } - - /** - * Helper function to retrieve the sort arguments if any are exposed. - * - * @param \Drupal\views\Plugin\views\display\DisplayPluginInterface $display - * The display plugin. - * @param $id - * The plugin derivative id. - * - * @return array - * The sort arguments if any exposed sorts are available. - */ - protected function getSortArguments(DisplayPluginInterface $display, $id) { - $sorts = array_filter($display->getOption('sorts') ?: [], function ($sort) { - return $sort['exposed']; - }); - return $sorts ? [ - 'sortDirection' => [ - 'type' => 'ViewSortDirection', - 'default' => 'asc', - ], - 'sortBy' => [ - 'type' => StringHelper::camelCase($id, 'sort', 'by'), - ], - ] : []; - } - - /** - * Helper function to return the filter argument if applicable. - * - * @param \Drupal\views\Plugin\views\display\DisplayPluginInterface $display - * The display plugin. - * @param $id - * The plugin derivative id. - * - * @return array - * The filter argument if any exposed filters are available. - */ - protected function getFilterArguments(DisplayPluginInterface $display, $id) { - $filters = array_filter($display->getOption('filters') ?: [], function($filter) { - return array_key_exists('exposed', $filter) && $filter['exposed']; - }); - - return !empty($filters) ? [ - 'filter' => [ - 'type' => $display->getGraphQLFilterInputName(), - ], - ] : []; - } - - /** - * Helper function to retrieve the pager arguments if the display is paged. - * - * @param \Drupal\views\Plugin\views\display\DisplayPluginInterface $display - * The display plugin. - * - * @return array - * An array of pager arguments if the view display is paged. - */ - protected function getPagerArguments(DisplayPluginInterface $display) { - return $this->isPaged($display) ? [ - 'page' => ['type' => 'Int', 'default' => $this->getPagerOffset($display)], - 'pageSize' => ['type' => 'Int', 'default' => $this->getPagerLimit($display)], - ] : []; - } - - /** - * Helper function to retrieve the types that the view can be attached to. - * - * @param \Drupal\views\Plugin\views\display\DisplayPluginInterface $display - * The display plugin. - * @param array $arguments - * An array containing information about the available arguments. - * @return array - * An array of additional types the view can be embedded in. - */ - protected function getTypes(DisplayPluginInterface $display, array $arguments) { - $types = ['Root']; - - if (($entity_type = $display->getOption('entity_type'))) { - $types = array_merge($types, [StringHelper::camelCase($entity_type)]); - - if (($bundles = $display->getOption('bundles'))) { - $types = array_merge($types, array_map(function ($bundle) use ($entity_type) { - return StringHelper::camelCase($entity_type, $bundle); - }, $bundles)); - } - } - - if (empty($arguments)) { - return $types; - } - - foreach ($arguments as $argument) { - // Depending on whether bundles are known, we expose the view field - // either on the interface (e.g. Node) or on the type (e.g. NodePage) - // level. Here we specify types managed by other graphql_* modules, - // yet we don't define these modules as dependencies. If types are not - // in the schema, the resulting GraphQL field will be attached to - // nowhere, so it won't go into the schema. - if (empty($argument['bundles']) && empty($argument['entity_type'])) { - continue; - } - - if (empty($argument['bundles'])) { - $types = array_merge($types, [StringHelper::camelCase($argument['entity_type'])]); - } - else { - $types = array_merge($types, array_map(function ($bundle) use ($argument) { - return StringHelper::camelCase($argument['entity_type'], $bundle); - }, array_keys($argument['bundles']))); - } - } - - return $types; - } - } diff --git a/src/ViewDeriverHelperTrait.php b/src/ViewDeriverHelperTrait.php index a64325b..539f4a6 100644 --- a/src/ViewDeriverHelperTrait.php +++ b/src/ViewDeriverHelperTrait.php @@ -117,7 +117,17 @@ protected function getPagerArguments(DisplayPluginInterface $display) { * @return array * An array of additional types the view can be embedded in. */ - protected function getTypes(array $arguments, array $types = ['Root']) { + protected function getTypes(DisplayPluginInterface $display, array $arguments, array $types = ['Root']) { + + if (($entity_type = $display->getOption('entity_type'))) { + $types = array_merge($types, [StringHelper::camelCase($entity_type)]); + + if (($bundles = $display->getOption('bundles'))) { + $types = array_merge($types, array_map(function ($bundle) use ($entity_type) { + return StringHelper::camelCase($entity_type, $bundle); + }, $bundles)); + } + } if (empty($arguments)) { return $types;