| Conditions | 10 |
| Paths | 27 |
| Total Lines | 93 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 62 | public function render(ElementInterface $element) |
||
| 63 | { |
||
| 64 | $name = $element->getName(); |
||
| 65 | if (empty($name) && $name !== 0) { |
||
|
|
|||
| 66 | throw new \DomainException( |
||
| 67 | sprintf( |
||
| 68 | '%s requires that the element has an assigned name; none discovered', |
||
| 69 | __METHOD__ |
||
| 70 | ) |
||
| 71 | ); |
||
| 72 | } |
||
| 73 | |||
| 74 | $renderer = $this->getView(); |
||
| 75 | |||
| 76 | /* @var \Zend\View\Helper\HeadScript $headscript */ |
||
| 77 | $headscript = $renderer->plugin('headscript'); |
||
| 78 | $basepath = $renderer->plugin('basepath'); |
||
| 79 | |||
| 80 | $headscript->appendFile($basepath('js/tinymce/tinymce.jquery.min.js')); |
||
| 81 | $headscript->prependFile($basepath('js/jquery.min.js')); |
||
| 82 | |||
| 83 | $headscript->offsetSetScript( |
||
| 84 | '1000_tinymce_' . $this->getTheme(), |
||
| 85 | ' |
||
| 86 | $(document).ready(function() { |
||
| 87 | tinyMCE.init({' . $this->additionalOptions() . ', |
||
| 88 | setup: function(editor) { |
||
| 89 | setPlaceHolder = function(editor, show) { |
||
| 90 | placeHolder = $("#placeholder-" + editor.id); |
||
| 91 | if (placeHolder.length == 1) { |
||
| 92 | if (show && editor.getContent() == "") { |
||
| 93 | placeHolder.show(); |
||
| 94 | } |
||
| 95 | else { |
||
| 96 | placeHolder.hide(); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | }, |
||
| 100 | editor.on("focus", function(e) { |
||
| 101 | setPlaceHolder(editor, false); |
||
| 102 | }); |
||
| 103 | editor.on("blur", function(e) { |
||
| 104 | setPlaceHolder(editor, true); |
||
| 105 | if (editor.isDirty()) { |
||
| 106 | //console.log("blur event", e); |
||
| 107 | editor.save(); |
||
| 108 | var container = e.target.bodyElement; |
||
| 109 | $(container).parents("html").addClass("yk-changed"); |
||
| 110 | var form = $(container).parents("form"); |
||
| 111 | //console.log("form", form, container); |
||
| 112 | form.submit(); |
||
| 113 | $(form).on("yk.forms.done", function(){ |
||
| 114 | console.log("done"); |
||
| 115 | //$(container).parents("html").removeClass("yk-changed"); |
||
| 116 | }); |
||
| 117 | } |
||
| 118 | }); |
||
| 119 | } |
||
| 120 | }); |
||
| 121 | });' |
||
| 122 | ); |
||
| 123 | |||
| 124 | $attributes = $element->getAttributes(); |
||
| 125 | $attributes['name'] = $name; |
||
| 126 | $attributes['id'] = $name; |
||
| 127 | $content = $element->getValue(); |
||
| 128 | if (!isset($content)) { |
||
| 129 | $content = ''; |
||
| 130 | } |
||
| 131 | if (is_string($content)) { |
||
| 132 | |||
| 133 | $class = array_key_exists('class', $attributes)?$attributes['class']:''; |
||
| 134 | $class .= (empty($class)?:' ') . ' tinymce_' . $this->getTheme(); |
||
| 135 | $attributes['class'] = $class; |
||
| 136 | $placeHolder = ''; |
||
| 137 | $elementOptions = $element->getOptions(); |
||
| 138 | if (array_key_exists('placeholder', $elementOptions) && !empty($elementOptions['placeholder'])) { |
||
| 139 | $placeHolder = '<div id="placeholder-' . $name . '" style="border: 0 none; position: relative; top: 0ex; left: 10px; color: #aaa; height: 0px; overflow: visible;' . |
||
| 140 | (empty($content)?'':'display:none;') . |
||
| 141 | '">' . $this->translator->translate($elementOptions['placeholder']) . '</div>'; |
||
| 142 | } |
||
| 143 | return |
||
| 144 | $placeHolder |
||
| 145 | . sprintf( |
||
| 146 | '<div %s >%s</div>', |
||
| 147 | $this->createAttributesString($attributes), |
||
| 148 | $content |
||
| 149 | ); |
||
| 150 | |||
| 151 | } else { |
||
| 152 | return (string) $content; |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 220 |