-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UNRI2-113, UNRI2-105, and UNRI2-106 PR's combined into one. #6
Changes from all commits
f7b1ca3
7783bc1
09b0491
dc513dc
23ef0f6
5a53c2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Hook implementations. | ||
*/ | ||
|
||
use Drupal\Core\Asset\AttachedAssetsInterface; | ||
use Drupal\paragraphs\ParagraphInterface; | ||
use Drupal\media\MediaInterface; | ||
|
||
/** | ||
* Implements hook_ENTITY_TYPE_presave(). | ||
*/ | ||
function dgi_3d_viewer_media_presave(MediaInterface $media) { | ||
if ($media->bundle() !== '3d_object') { | ||
return; | ||
} | ||
$camera = $media->get('field_camera')->referencedEntities()[0] ?? NULL; | ||
|
||
if (!$camera) { | ||
$media->field_customcamera = NULL; | ||
return; | ||
} | ||
|
||
$camera_settings = dgi_3d_viewer_flatten_camera_values($camera); | ||
|
||
$media->field_customcamera = serialize($camera_settings); | ||
} | ||
|
||
/** | ||
* Flatten camera values. | ||
*/ | ||
function dgi_3d_viewer_flatten_camera_values(ParagraphInterface $camera) { | ||
$type = $camera->bundle(); | ||
$camera_settings = [ | ||
'settings' => [ | ||
'near' => $camera->field_near->value, | ||
'far' => $camera->field_far->value, | ||
'position' => [ | ||
'x' => $camera->field_position_x->value, | ||
'y' => $camera->field_position_y->value, | ||
'z' => $camera->field_position_z->value, | ||
], | ||
'rotation' => [ | ||
'x' => $camera->field_rotation_x->value, | ||
'y' => $camera->field_rotation_y->value, | ||
'z' => $camera->field_rotation_z->value, | ||
], | ||
], | ||
]; | ||
switch ($type) { | ||
case 'orthographic_camera_settings': | ||
$camera_settings['type'] = 'OrthographicCamera'; | ||
$camera_settings['settings']['top'] = $camera->field_top->value; | ||
$camera_settings['settings']['bottom'] = $camera->field_bottom->value; | ||
$camera_settings['settings']['left'] = $camera->field_left->value; | ||
$camera_settings['settings']['right'] = $camera->field_right->value; | ||
break; | ||
|
||
case 'perspective_camera_settings': | ||
$camera_settings['type'] = 'PerspectiveCamera'; | ||
$camera_settings['settings']['aspect'] = $camera->field_aspect->value; | ||
$camera_settings['settings']['fov'] = $camera->field_fov->value; | ||
break; | ||
} | ||
|
||
return $camera_settings; | ||
} | ||
Comment on lines
+31
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If, instead of rolling paragraphs, we rolled our own field type(s?) explicitly for the purpose, it could have all this (re)structuring built in to it. |
||
|
||
/** | ||
* Implements hook_js_settings_alter(). | ||
*/ | ||
function dgi_3d_viewer_js_settings_alter(array &$settings, AttachedAssetsInterface $assets) { | ||
// Check if prod split is enabled. | ||
$settings['isProd'] = \Drupal::config('config_split.config_split.prod')->get('status'); | ||
} | ||
Comment on lines
+71
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should really not be binding to some other arbitrary configuration... as in, strictly, this entire module should now be dependent on the ... we should either have a module-specific debug flag, or make use of Drupal core's devel/error reporting stuff, maybe https://github.com/discoverygarden/dgi-starter/blob/43a70275f535b94705b58d3b6997882efcd23892/config/sync/system.logging.yml#L3 ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Encountering in the context of D10 stuff, but anything not in core here should be declared in the
composer.json
.... though, I also wonder: How much are we actually dependent on? Grep'ing for
entity_reference_revisions
,field_group
,filehash
,islandora
andislandora_defaults
, only finding this info.yml. Only real direct non-core dependency isparagraphs
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Planning to adjust things in #16