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
Add image type #26
Add image type #26
Changes from 2 commits
d8882ef
364d4e5
eed1562
08e4e96
9046640
068a4d5
68da161
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,49 @@ | ||
<?php | ||
namespace plugin\struct\types; | ||
|
||
use plugin\struct\meta\ValidationException; | ||
|
||
class Img extends AbstractBaseType { | ||
|
||
protected $config = array( | ||
); | ||
|
||
/** | ||
* Output the stored data | ||
* | ||
* @param string|int $value the value stored in the database | ||
* @param \Doku_Renderer $R the renderer currently used to render the data | ||
* @param string $mode The mode the output is rendered in (eg. XHTML) | ||
* @return bool true if $mode could be satisfied | ||
*/ | ||
public function renderValue($value, \Doku_Renderer $R, $mode) { | ||
if (!empty($value)) { | ||
if (strpos($value, '://') === false) { | ||
$R->internalmedia($value); | ||
} else { | ||
$R->externalmedia($value); | ||
} | ||
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. Ah, now I understand what you meant. There's an easier way. The renderer object you are passed here is the same object you used earlier in startScope. You could simply store the hash in $renderer->info['struct_table_hash'] in startScope and remove it again in stopScope. Later check here, if the value is set and act accordingly. |
||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Return the editor to edit a single value | ||
* | ||
* @param string $name the form name where this has to be stored | ||
* @param string $value the current value | ||
* @return string html | ||
*/ | ||
public function valueEditor($name, $value) { | ||
$name = hsc($name); | ||
$value = hsc($value); | ||
|
||
$id = preg_replace('(\[|\])','',substr($name,strpos($name,'[')+1)); | ||
|
||
$html = "<input id=\"$id\" class=\"struct_img\" name=\"$name\" value=\"$value\" />"; | ||
$html .= "<button type=\"button\" class=\"struct_img\" id=\"$id"."Button\">"; | ||
$html .= "<img src=\"" . DOKU_BASE . "lib/images/toolbar/image.png\" height=\"16\" width=\"16\">"; | ||
$html .= "</button>"; | ||
return $html; | ||
} | ||
} |
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.
I believe we do not render empty values? We should set up some rules on what types do not need to check themselves (like validate() is never called for blank fields).