forked from marcostoll/processwire-fieldtype-assisted-url
-
Notifications
You must be signed in to change notification settings - Fork 4
/
InputfieldAssistedURL.module
72 lines (64 loc) · 1.83 KB
/
InputfieldAssistedURL.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* Class InputfieldAssistedURL
*
* @author Marco Stoll <[email protected]>
* @link http://core4.de CORE4 GmbH & Co. KG
* @copyright Copyright (c) 2015, CORE4 GmbH & Co. KG
* @license MIT http://opensource.org/licenses/MIT
* @version 1.0.0
* @see http://www.processwire.com
* @filesource
*/
/**
* Class InputfieldAssistedURL
*/
class InputfieldAssistedURL extends Inputfield {
/**
* @var Page
*/
protected $page;
/**
* Get information about this module
*
* @return array
*/
public static function getModuleInfo() {
return [
'title' => 'AssistedURL Input',
'version' => '2.0.1',
'summary' => 'Input field for assisted urls.',
'requires' => 'FieldtypeAssistedURL',
'author' => 'Marco Stoll, Adrian Jones'
];
}
/**
* Sets the current page
*
* @param Page $page
*/
public function setPage(Page $page) {
$this->page = $page;
}
/**
* Render the entire input area for Events
*/
public function ___render() {
$field = new InputfieldURL();
$field->set('name', $this->attr('name'));
$field->set('value', $this->attr('value'));
$field->set('class', 'InputfieldAssistedURLInput');
$btn = $this->modules->get('InputfieldButton');
$btn->attr('id', $this->attr('name') . "_assistedurl_open");
$page = $this->page;
$n = 0;
while(wireInstanceOf($page, 'RepeaterPage') && ++$n < 10) {
$page = $page->getForPage();
}
$btn->attr('data-page-id', $page->id);
$btn->class .= " InputfieldAssistedURLOpen";
$btn->icon = 'link';
$btn->value = '';
return $btn->render() . '<div class="InputfieldAssistedUrlText">' . $field->render() . '</div>';
}
}