PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.1.4
Admin Columns v7.1.4
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Value / ExtendedValueLink.php
codepress-admin-columns / classes / Value Last commit date
Extended 2 days ago ExtendedValueLink.php 2 days ago ExtendedValueLinkFactory.php 2 days ago ExtendedValueRegistry.php 2 days ago
ExtendedValueLink.php
103 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\Value;
6
7 final class ExtendedValueLink
8 {
9 private string $view;
10
11 private array $attributes;
12
13 /**
14 * @var mixed
15 */
16 private $id;
17
18 private string $label;
19
20 private array $params;
21
22 public function __construct(string $label, $id, string $view, array $attributes = [], array $params = [])
23 {
24 $this->view = $view;
25 $this->attributes = $attributes;
26 $this->id = $id;
27 $this->label = $label;
28 $this->params = $params;
29 }
30
31 protected function with_attribute(string $key, string $value): self
32 {
33 $this->attributes[$key] = $value;
34
35 return new self($this->label, $this->id, $this->view, $this->attributes, $this->params);
36 }
37
38 public function with_params($params): self
39 {
40 return new self($this->label, $this->id, $this->view, $this->attributes, $params);
41 }
42
43 public function with_title(string $title): self
44 {
45 return $this->with_attribute('title', $title);
46 }
47
48 public function with_edit_link(string $edit_link): self
49 {
50 return $this->with_attribute('edit_link', $edit_link);
51 }
52
53 public function with_download_link(string $download_link): self
54 {
55 return $this->with_attribute('download_link', $download_link);
56 }
57
58 public function with_view_link(string $download_link): self
59 {
60 return $this->with_attribute('view_link', $download_link);
61 }
62
63 public function with_class(string $class): self
64 {
65 return $this->with_attribute('class', $class);
66 }
67
68 public function render(): string
69 {
70 $attributes = $this->attributes;
71 $attribute_markup = [];
72
73 if (isset($attributes['title']) && $attributes['title']) {
74 $attribute_markup[] = sprintf('data-modal-title="%s"', esc_attr($attributes['title']));
75 }
76 if (isset($attributes['edit_link']) && $attributes['edit_link']) {
77 $attribute_markup[] = sprintf('data-modal-edit-link="%s"', esc_url($attributes['edit_link']));
78 }
79 if (isset($attributes['download_link']) && $attributes['download_link']) {
80 $attribute_markup[] = sprintf('data-modal-download-link="%s"', esc_url($attributes['download_link']));
81 }
82 if (isset($attributes['view_link']) && $attributes['view_link']) {
83 $attribute_markup[] = sprintf('data-modal-view-link="%s"', esc_url($attributes['view_link']));
84 }
85 if (isset($attributes['class']) && $attributes['class']) {
86 $attribute_markup[] = sprintf('data-modal-class="%s"', esc_attr($attributes['class']));
87 }
88
89 if (! empty($this->params)) {
90 $attribute_markup[] = sprintf('data-modal-params="%s"', esc_attr(json_encode($this->params) ?: ''));
91 }
92
93 $attribute_markup[] = sprintf('data-modal-id="%s"', esc_attr((string)$this->id));
94 $attribute_markup[] = sprintf('data-view="%s"', esc_attr($this->view));
95
96 return sprintf(
97 '<a style="border-bottom: 1px dotted;" data-modal-value %s>%s</a>',
98 implode(' ', $attribute_markup),
99 $this->label
100 );
101 }
102 }
103