PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Document / Models / Elements / Component.php

Component.php in Depicter — Popup & Slider Builder trunk, at app/src/Document/Models/Elements/Component.php

66 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\Document\Models\Elements;
4
5 use Averta\Core\Utility\Arr;
6 use Averta\Core\Utility\JSON;
7 use Depicter\Document\Models\Common\Styles;
8 use Depicter\Document\Models\Element;
9 use Depicter\Html\Html;
10
11 class Component extends Element
12 {
13
14 /**
15 * Render arrow markup
16 *
17 * @return \TypeRocket\Html\Html|void
18 * @throws \JsonMapper_Exception
19 */
20 public function render() {
21 $args = $this->getDefaultAttributes();
22 return Html::div( $args );
23 }
24
25 public function getDefaultAttributes(){
26 $parentAttrs = parent::getDefaultAttributes(); // TODO: Change the autogenerated stub
27
28 $options = $this->options;
29 foreach( $options as $key => $option ) {
30 if ( strpos( $key, 'imageAsset' ) ) {
31 if ( is_object( $options->$key ) ) {
32 $source = $this->hasDataSheet() ? $this->maybeReplaceDataSheetTags( $options->$key->src ) : $options->$key->src;
33 $options->$key->srcset = \Depicter::media()->getSrcSet( $source );
34 $options->$key->src = \Depicter::media()->getSourceUrl( $source );
35 } else {
36 // $option is string and is the src id of image asset
37 $source = $this->hasDataSheet() ? $this->maybeReplaceDataSheetTags( $option ) : $option;
38 $options->$key = \Depicter::media()->getSourceUrl( $source );
39 }
40 } else if ( $key == 'choices' ) {
41 foreach( $option as $optionKey => $choice ) {
42 foreach ( $choice as $choiceKey => $value ) {
43 if ( strpos( $choiceKey, 'imageAsset' ) ) {
44 $source = $this->hasDataSheet() ? $this->maybeReplaceDataSheetTags( $value ) : $value;
45 $options->$key[ $optionKey ]->$choiceKey = [
46 'src' => \Depicter::media()->getSourceUrl( $source ),
47 'srcset' => \Depicter::media()->getSrcSet( $source )
48 ];
49 }
50 }
51 }
52 }
53 }
54
55 $componentProps = JSON::encode( $options );
56 $componentProps = str_replace( ':imageAsset', '', $componentProps );
57
58 $attrs = [
59 'data-component-type' => $this->componentType,
60 'data-component-props' => $componentProps
61 ];
62
63 return Arr::merge( $attrs, $parentAttrs );
64 }
65 }
66