Skip to content
Snippets Groups Projects
Commit ce3f801f authored by Alberto Paderno's avatar Alberto Paderno Committed by Hari Venu
Browse files

Issue #3358798: Fix the issues reported by phpcs

parent 29bd466b
Branches
Tags
1 merge request!3Issue #3358798: Fix the issues reported by phpcs
Pipeline #367912 passed with warnings
################
# GitLabCI template for Drupal projects.
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification.
# It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
# As long as you include the project, ref and three files below, any future updates added by the Drupal Association will be used in your
# pipelines automatically. However, you can modify this template if you have additional needs for your project.
# The full documentation is on https://project.pages.drupalcode.org/gitlab_templates/
################
# For information on alternative values for 'ref' see https://project.pages.drupalcode.org/gitlab_templates/info/templates-version/
# To test a Drupal 7 project, change the first include filename from .main.yml to .main-d7.yml
include:
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- "/includes/include.drupalci.main.yml"
- "/includes/include.drupalci.variables.yml"
- "/includes/include.drupalci.workflows.yml"
################
# Pipeline configuration variables are defined with default values and descriptions in the file
# https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
# Uncomment the lines below if you want to override any of the variables. The following is just an example.
################
# variables:
# SKIP_ESLINT: '1'
# OPT_IN_TEST_NEXT_MAJOR: '1'
# _CURL_TEMPLATES_REF: 'main'
Google Model Viewer
-----------------
gmv(Google Model Viewer) is a web component that makes rendering interactive 3D models.
gmv provides field type for drupal users to upload their 3D files(.zip). The 3D file format should be glTF.
file like https://sketchfab.com/features/gltf
gmv(Google Model Viewer) is a web component that makes rendering interactive
3D models.
gmv provides field type for drupal users to upload their 3D files(.zip). The 3D
file format should be glTF. file like https://sketchfab.com/features/gltf.
Here is the gmv field for 3D Objects...!!! You can create 3D files and upload the .zip file to the Drupal gmv field in your content.
Here is the gmv field for 3D Objects...!!! You can create 3D files and upload
the .zip file to the Drupal gmv field in your content.
Installation
------------
......@@ -27,4 +29,3 @@ As per the https://modelviewer.dev/
* Shadow Intensity - Shadow intensity for 3D object
* Height in pixel - Height of the 3D object.
* Width in pixel - Width of the 3D object.
......@@ -5,4 +5,3 @@ package: Field types
core_version_requirement: ^8 || ^9 || ^10
dependencies:
- drupal:file
\ No newline at end of file
......@@ -2,4 +2,4 @@ gmv_files:
header: true
version: VERSION
js:
https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js: { type: external, minified: true, attributes: { type: module } }
\ No newline at end of file
https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js: { type: external, minified: true, attributes: { type: module } }
<?php
/**
* @file
* Implement of theme hook.
*/
/**
* Implements hook_theme().
* Implement of theme hook.
*/
function gmv_theme() {
return [
'gmv_image_formatter' => [
'variables' => [
'uri' => NULL,
'camera' => NULL,
'touch_action' => NULL,
'shadow' => NULL,
'skybox_image' => NULL,
],
$paramets = [
'gmv_image_formatter' =>
[
'variables' =>
[
'uri' => NULL,
'camera' => NULL,
'touch_action' => NULL,
'shadow' => NULL,
'skybox_image' => NULL,
],
],
];
return $paramets;
}
......@@ -2,10 +2,10 @@
namespace Drupal\gmv\Plugin\Field\FieldFormatter;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Entity\File;
/**
* Plugin implementation of the 'field_three_dee_object' formatter.
......@@ -20,6 +20,31 @@ use Drupal\file\Entity\File;
*/
class ThreeDeeObjectFieldFormatter extends FormatterBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The file URL generator.
*
* @var \Drupal\Core\File\FileUrlGeneratorInterface
*/
protected $fileUrlGenerator;
/**
* FileRepository constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->fileUrlGenerator = $fileUrlGenerator;
$this->entityTypeManager = $entityTypeManager;
}
/**
* {@inheritdoc}
*/
......@@ -51,39 +76,42 @@ class ThreeDeeObjectFieldFormatter extends FormatterBase {
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$fileStorage = $this->entityTypeManager->getStorage('file');
$elements = [];
foreach ($items as $delta => $item) {
$background_img_path = NULL;
$path = NULL;
if($item->skybox_image_id != NULL) {
$background_img_file = File::load($item->skybox_image_id);
if( $background_img_file->status->value != 1 ) {
if ($item->skybox_image_id != NULL) {
$background_img_file = $fileStorage->load($item->skybox_image_id);
if ($background_img_file->status->value != 1) {
$background_img_file->setPermanent();
$background_img_file->save();
}
$background_img_path = \Drupal::service('file_url_generator')->generateAbsoluteString($background_img_file->getFileUri());
}
$background_img_path = $this->fileUrlGenerator->generateAbsoluteString($background_img_file->getFileUri());
}
if ($item->three_dee_fid) {
$file = File::load($item->three_dee_fid);
$path = \Drupal::service('file_url_generator')->generateAbsoluteString($file->getFileUri());
if ($item->three_dee_fid) {
$file = $fileStorage->load($item->three_dee_fid);
$path = $this->fileUrlGenerator->generateAbsoluteString($file->getFileUri());
}
$elements[$delta] = [
'#theme' => 'gmv_image_formatter',
'#uri' => $path,
'#camera' => $item->camera,
'#touch_action' => $item->touch_action,
'#shadow' => $item->shadow,
'#skybox_image' => $background_img_path,
'#skybox_image' => $background_img_path,
];
}
return $elements;
}
}
\ No newline at end of file
}
......@@ -2,12 +2,12 @@
namespace Drupal\gmv\Plugin\Field\FieldType;
use Drupal\Core\Archiver\Zip;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\file\Plugin\Field\FieldType\FileItem;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\file\Entity\File;
use Drupal\Core\Archiver\Zip;
use Drupal\file\Plugin\Field\FieldType\FileItem;
/**
* Plugin implementation of the 'field_three_dee_object' field type.
......@@ -30,12 +30,12 @@ class ThreeDeeObject extends FileItem {
*/
public static function defaultFieldSettings() {
$settings = [
'camera' => 1,
'touch_action' => 'pan-left',
'shadow' => 1,
'file_extensions' => 'zip',
'file_directory' => 'gmv',
'filesize' => '50M'
'camera' => 1,
'touch_action' => 'pan-left',
'shadow' => 1,
'file_extensions' => 'zip',
'file_directory' => 'gmv',
'filesize' => '50M',
] + parent::defaultFieldSettings();
return $settings;
}
......@@ -132,27 +132,27 @@ class ThreeDeeObject extends FileItem {
->setDescription(t("Height in pixel.")),
'width' => DataDefinition::create('integer')
->setLabel(t('Width'))
->setDescription(t("Width in pixel.")),
->setDescription(t("Width in pixel.")),
] + parent::propertyDefinitions($field_definition);
}
/**
* {@inheritdoc}
*/
public function preSave() {
public function preSave() {
$fileEntity = $this->get('entity')->getValue();
$fname = $fileEntity->filename->value;
$dir_path = pathinfo($fname, PATHINFO_FILENAME);
$path = 'public://gmv'.'/'.$dir_path;
$fname = $fileEntity->filename->value;
$dir_path = pathinfo($fname, PATHINFO_FILENAME);
$path = 'public://gmv/' . $dir_path;
$data = $this->getValue();
$skybox_image_id = (isset($data['file'][0])) ? $data['file'][0] : NULL;
$this->skybox_image_id = $skybox_image_id;
$this->skybox_image_id = $skybox_image_id;
if (TRUE !== is_dir($path)) {
$fid = $this->processFile();
$this->three_dee_fid = $fid;
}
$this->three_dee_fid = $fid;
}
parent::preSave();
}
/**
......@@ -198,14 +198,14 @@ class ThreeDeeObject extends FileItem {
* Function return zip file object, folder uri and filename.
*/
protected function threedeeZipfile(File $file) {
$uri = $file->getFileUri();
$uri = $file->getFileUri();
if (file_exists($uri)) {
$file_system = \Drupal::service('file_system');
$realPath = $file_system->realpath($uri);
$zipFile = new Zip($realPath);
$pathinfo = pathinfo($uri);
$folderUri = $pathinfo['dirname'];
$cleanFilename = $pathinfo['filename'];
$folderUri = $pathinfo['dirname'];
$cleanFilename = $pathinfo['filename'];
$folderUri = $folderUri . '/' . $cleanFilename;
$file_system->prepareDirectory($folderUri);
......@@ -218,4 +218,4 @@ class ThreeDeeObject extends FileItem {
return NULL;
}
}
\ No newline at end of file
}
......@@ -41,13 +41,13 @@ class ThreeDeeObjectWidget extends FileWidget {
$elements = parent::settingsForm($form, $form_state);
return $elements;
}
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$item = $items[$delta];
$item = $items[$delta];
$element += [
'camera' => [
'#type' => 'checkbox',
......@@ -73,8 +73,8 @@ class ThreeDeeObjectWidget extends FileWidget {
'initial' => 'initial',
'revert' => 'revert',
'revert-layer' => 'revert-layer',
'unset' => 'unset'
],
'unset' => 'unset',
],
'#description' => $this->t('touch-action CSS property'),
'#default_value' => $item->touch_action,
],
......@@ -89,15 +89,15 @@ class ThreeDeeObjectWidget extends FileWidget {
'#type' => 'managed_file',
'#title' => $this->t('Background Image'),
'#upload_location' => 'public://skyboximage',
'#default_value' => isset($item->skybox_image_id) ? array($item->skybox_image_id) : NULL,
'#default_value' => isset($item->skybox_image_id) ? [$item->skybox_image_id] : NULL,
],
'three_dee_fid' => [
'#type' => 'hidden',
'#value' => isset($item->three_dee_fid) ? $item->three_dee_fid : NULL,
]
'#value' => $item->three_dee_fid ?? NULL,
],
];
return $element;
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment