Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Commit

Permalink
fix(Features/AdminComponentPreview): use correct assets path and url (#…
Browse files Browse the repository at this point in the history
…170)

* fix(Features/AdminComponentPreview/functions): Fixed assets path and url

Usinng Asset Utils to load components preview images

* refactor(Features/AdminComponentPreview/functions): Refactored string concatenation to interpolation

* refactor(Features/AdminComponentPreview/functions): Refactored string concatenation to interpolation

Refactored string concatenation to interpolation for assets (preview images-
  • Loading branch information
vandebled authored and Doğa Gürdal committed May 11, 2017
1 parent 99aa561 commit e2cb5e6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Features/AdminComponentPreview/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function enqueueComponentScripts()

// add data to the javascript
$data = [
'templateDirectoryUri' => get_template_directory_uri()
'templateDirectoryUri' => get_template_directory_uri() . '/dist'
];
wp_localize_script('Flynt/Features/AdminComponentPreview', 'wpData', $data);
}
Expand All @@ -37,13 +37,12 @@ function enqueueComponentScripts()
if (is_user_logged_in() || is_admin()) {
if (is_admin()) {
add_action('admin_enqueue_scripts', NS . 'enqueueComponentScripts');

// add image to the flexible content component name
add_filter('acf/fields/flexible_content/layout_title', function ($title, $field, $layout, $i) {
$componentPath = "/Components/$layout[name]/";
$componentPreviewDesktopPath = get_template_directory() . $componentPath . 'preview-desktop.jpg';
$componentPreviewDesktopUrl = get_template_directory_uri() . $componentPath . 'preview-desktop.jpg';

$componentName = ucfirst($layout['name']);
$componentPath = "Components/{$componentName}";
$componentPreviewDesktopPath = Asset::requirePath("{$componentPath}/preview-desktop.jpg") ;
$componentPreviewDesktopUrl = Asset::requireUrl("{$componentPath}/preview-desktop.jpg");
if (is_file($componentPreviewDesktopPath)) {
$newTitle = '<span class="flyntComponentPreview">';
$newTitle .= '<img class="flyntComponentPreview-imageElement" src="' . $componentPreviewDesktopUrl . '" height="36px">';
Expand All @@ -59,8 +58,8 @@ function enqueueComponentScripts()
add_action('admin_bar_menu', function ($wpAdminBar) {
$title = __('Component Previews', 'flynt-starter-theme');
$wpAdminBar->add_menu([
'id' => 'toggleComponentPreviews',
'title' => $title
'id' => 'toggleComponentPreviews',
'title' => $title
]);
});
}
Expand Down

0 comments on commit e2cb5e6

Please sign in to comment.