Added the configuration for likes text and icon.
Closes #3502436
Merge request reports
Activity
94 95 'progress' => ['type' => 'none'], 95 96 ], 96 97 ]; 97 $form['label']['icon'] = [ 98 '#type' => 'html_tag', 99 '#tag' => 'i', 100 '#attributes' => [ 101 'class' => ['fa-solid', 'fa-heart'], 102 ], 103 ]; 98 $icon = \Drupal::config('like.settings')->get('image'); 99 $file = File::load($icon); 100 $image_url = $file ? $file->createFileUrl() : ''; 101 dump($image_url); changed this line in version 2 of the diff
94 95 'progress' => ['type' => 'none'], 95 96 ], 96 97 ]; 97 $form['label']['icon'] = [ 98 '#type' => 'html_tag', 99 '#tag' => 'i', 100 '#attributes' => [ 101 'class' => ['fa-solid', 'fa-heart'], 102 ], 103 ]; 98 $icon = \Drupal::config('like.settings')->get('image'); 99 $file = File::load($icon); 100 $image_url = $file ? $file->createFileUrl() : ''; 101 dump($image_url); 102 if($file){ changed this line in version 2 of the diff
98 '#type' => 'html_tag', 99 '#tag' => 'i', 100 '#attributes' => [ 101 'class' => ['fa-solid', 'fa-heart'], 102 ], 103 ]; 98 $icon = \Drupal::config('like.settings')->get('image'); 99 $file = File::load($icon); 100 $image_url = $file ? $file->createFileUrl() : ''; 101 dump($image_url); 102 if($file){ 103 $form['label']['image'] = [ 104 '#type' => 'html_tag', 105 '#tag' => 'img', 106 '#attributes' => [ 107 'src' => $image_url, changed this line in version 2 of the diff
178 197 * Returns the likes text for the item. 179 198 */ 180 199 protected function likesTxt(int $value): string { 181 return $this->t('(<span>@value</span>) Likes', ['@value' => $value]); 200 $likes = \Drupal::config('like.settings')->get('like_text'); 201 $likes_text = !empty($likes) ? $likes : 'Likes'; 202 return $this->t('(<span>@value</span>) @likes', ['@value' => $value, '@likes' => $likes_text]); changed this line in version 3 of the diff
99 100 '#default_value' => $config->get('like_cookie_expiry_time'), 100 101 ]; 101 102 103 $form['like_text'] = [ 104 '#type' => 'textfield', 105 '#title' => $this->t('Like Text'), 106 '#description' => $this->t('Please enter the text to display'), 107 '#default_value' => $config->get('like_text'), 108 ]; 109 110 111 if($config->get('image')){ 112 $file = File::load($config->get('image')); 113 $form['like_icon'] = [ 114 '#type' => 'managed_file', changed this line in version 2 of the diff
120 136 parent::submitForm($form, $form_state); 121 137 $config = $this->config('like.settings'); 122 138 $config->set('enabled_entity_types', $form_state->getValue('enabled_entity_types')); 139 $config->set('like_text', $form_state->getValue('like_text')); Whenever adding new properties, we need to reflect them with their right type in the config schema https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-schemametadata
7 7 label: 'Enabled entity types' 8 8 sequence: 9 9 type: string 10 like_text: 11 type: string 12 label: 'Like button text' 13 icon_class: 14 type: string 15 label: 'CSS class for like button icon' 10 16 like_cookie_expiry_time: 11 17 type: integer 12 label: 'Like Cookie Expiry Time' 18 label: 'Cookie expiry time in seconds' changed this line in version 7 of the diff
94 95 'progress' => ['type' => 'none'], 95 96 ], 96 97 ]; 97 $form['label']['icon'] = [ 98 '#type' => 'html_tag', 99 '#tag' => 'i', 100 '#attributes' => [ 101 'class' => ['fa-solid', 'fa-heart'], 102 ], 103 ]; 98 $icon = \Drupal::config('like.settings')->get('icon_class'); 99 if($icon) { changed this line in version 7 of the diff
178 192 * Returns the likes text for the item. 179 193 */ 180 194 protected function likesTxt(int $value): string { 181 return $this->t('(<span>@value</span>) Likes', ['@value' => $value]); 195 $likes = \Drupal::config('like.settings')->get('like_text'); changed this line in version 7 of the diff
94 95 'progress' => ['type' => 'none'], 95 96 ], 96 97 ]; 97 $form['label']['icon'] = [ 98 '#type' => 'html_tag', 99 '#tag' => 'i', 100 '#attributes' => [ 101 'class' => ['fa-solid', 'fa-heart'], 102 ], 103 ]; 98 $icon = \Drupal::config('like.settings')->get('icon_class'); changed this line in version 7 of the diff
99 99 '#default_value' => $config->get('like_cookie_expiry_time'), 100 100 ]; 101 101 102 $form['like_text'] = [ 103 '#type' => 'textfield', 104 '#title' => $this->t('Like Text'), 105 '#description' => $this->t('Please enter the text to display'), 94 95 'progress' => ['type' => 'none'], 95 96 ], 96 97 ]; 97 $form['label']['icon'] = [ 98 '#type' => 'html_tag', 99 '#tag' => 'i', 100 '#attributes' => [ 101 'class' => ['fa-solid', 'fa-heart'], 102 ], 103 ]; 98 $icon = \Drupal::config('like.settings')->get('icon_class'); 99 if($icon) { 100 $form['label']['image'] = [ changed this line in version 7 of the diff
Please register or sign in to reply