Skip to content

Commit

Permalink
Merge pull request #4 from zngly/bug/2/gallery
Browse files Browse the repository at this point in the history
Bug/2/gallery
  • Loading branch information
zngly-vlad authored Jul 22, 2022
2 parents acda6fb + de0d123 commit 5cd68f6
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 21 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
}
]
}
17 changes: 5 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.11",
"version": "1.0.12",
"name": "zngly/wp-graphql-acf-mutations",
"description": "ACF Mutations for WP GraphQL",
"homepage": "https://github.com/zngly/wp-graphql-acf-mutations",
Expand Down Expand Up @@ -63,26 +63,19 @@
"spatie/file-system-watcher": "^1.1"
},
"autoload-dev": {
"psr-4": {
"WPGraphQL\\ACF\\Mutations\\": "src/",
"Zngly\\ACF\\Scripts\\": "scripts/",
"\\": "wordpress/vendor/"
},
"classmap": [
"src",
"scripts",
"wordpress/vendor"
"src/",
"scripts/",
"dev/"
]
},
"autoload": {
"psr-4": {
"WPGraphQL\\ACF\\Mutations\\": "src/"
},
"classmap": [
"src/"
]
},
"scripts": {
"install": "composer install --no-dev",
"install:dev": [
"Zngly\\ACF\\Scripts\\Install::run"
],
Expand Down
3 changes: 3 additions & 0 deletions dev/acf/acf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// load acf configuration here
38 changes: 38 additions & 0 deletions dev/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Zngly\ACF\Dev;

require_once __DIR__ . '/acf/acf.php';

class Init
{

public static function run()
{
add_action('init', function () {
Init::welcome_message();
Init::plugins();
});
}

public static function welcome_message()
{
echo '<script>';
echo 'console.log("Welcome to Zngly WP-Graphq-ACF-Mutations");';
echo '</script>';
}

public static function plugins()
{
// get all the activated plugins
$active_plugins = get_option('active_plugins');

// get all the plugins
$plugins = get_plugins();

// if a plugin is not activated, activate it
foreach ($plugins as $plugin_path => $plugin)
if (!in_array($plugin_path, $active_plugins))
activate_plugin($plugin_path);
}
}
82 changes: 82 additions & 0 deletions dev/query.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
mutation Content_Update_Mutation {
updateZnglyVideo(
input: {
id: "cG9zdDo5OTA2Mjg="
status: PENDING
tags: { nodes: [{ name: "tag" }, { name: "two" }, { name: "three" }, { name: "test" }], append: false }
}
) {
znglyVideo {
title
status
tags {
nodes {
name
}
}
}
}
}

query MyQuery5 {
znglyVideos(where: { status: PENDING }) {
nodes {
title
id
tags {
nodes {
name
}
}
}
}
}

query MyQuery2 {
users(first: 100) {
nodes {
id
databaseId
username
role
}
}
}

query AuthorIn {
znglyVideos(where: { author: 2 }) {
nodes {
title
author {
node {
username
databaseId
id
}
}
}
}
}

query setttings {
znglyInfo(id: "site-info", idType: SLUG) {
databaseId
znglyInfo {
address1
address2
address3
}
}
}

mutation MyMutation2 {
updateMediaItem(input: { id: "cG9zdDoxNzcw", coords: "testing" }) {
mediaItem {
id
title
fields {
coords
}
}
}
}
5 changes: 5 additions & 0 deletions dev/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Dev

This folder is only used when developing the project.

index.php - The Init class is loaded by an mu-plugin called zngly_autloader.php
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-graphql-acf-mutations",
"version": "1.0.11",
"version": "1.0.12",
"description": "wp-graphql-acf-mutations",
"homepage": "https://github.com/zngly/wp-graphql-acf-mutations#readme",
"author": "Vlad-Anton Medves",
Expand Down
16 changes: 13 additions & 3 deletions scripts/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@ private function modify_wordpress()
{
self::print("Modifying Wordpress...\n");

// add autoload to wp-config
$wordpress_dir = $this->root_dir . '/wordpress';
$wp_config_path = $wordpress_dir . '/wp-config-sample.php';

Utils::add_to_file($wp_config_path, "if(!defined('ABSPATH'))", 'require ABSPATH . "vendor/autoload.php";');
Utils::add_to_file($wordpress_dir . '/wp-config.php', "if(!defined('ABSPATH'))", 'require ABSPATH . "vendor/autoload.php";');

// load our dev code here
// create a new file called zngly.php in the mu-plugins folder
$zngly_path = Utils::format_path($wordpress_dir . '/wp-content/mu-plugins/zngly_autoloader.php');

// create the file
$zngly_file = fopen($zngly_path, 'w');
// write the contents
fwrite($zngly_file, "<?php\n\nuse Zngly\ACF\Dev\Init;\nInit::run();\n\n");
// close the file
fclose($zngly_file);

// delete all themes except twentytwentytwo
$themes_dir = $wordpress_dir . '/wp-content/themes';
Expand Down
14 changes: 14 additions & 0 deletions scripts/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ public static function copy_folder($src, $dest)
closedir($dir);
}

public static function regenerate_autoloader()
{
$root_dir = self::get_root_dir();

// execute composer dump-autoload -o
$command = "cd {$root_dir} && composer dump-autoload -o";
$output = exec($command);
echo $output;
}

public static function format_path(string $path)
{
return str_replace('\\', '/', $path);
}

public static function get_root_dir()
{
Expand Down
12 changes: 8 additions & 4 deletions scripts/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,26 @@ public static function run()
$plugin_folder = Utils::get_root_dir() . "/wordpress/wp-content/plugins/{$plugin_name}";

// watch for any file changes in the directory
self::watch_dirs([$src_folder, "{$plugin_folder}/{$plugin_name}.php"]);
self::watch_dirs([$src_folder, "{$plugin_folder}/{$plugin_name}.php"]);
}



// function to watch a directory for changes
public static function watch_dirs(array $dirs)
{
$root_dir = Utils::get_root_dir();
$plugins_folder = $root_dir . "/wordpress/wp-content/plugins/" . Utils::get_plugin_name();
$plugins_folder = Utils::format_path($root_dir . "/wordpress/wp-content/plugins/" . Utils::get_plugin_name());

Watch::paths(...$dirs)
->onAnyChange(function (string $type, string $path) use ($root_dir, $plugins_folder) {
// format path forwardslashes
$path = Utils::format_path($path);

// find the new path to the change
$path_parts = explode($root_dir, $path);
$new_path = $plugins_folder . $path_parts[1];

echo "{$type}: {$path}\n";

switch ($type) {
case Watch::EVENT_TYPE_DIRECTORY_CREATED:
mkdir($new_path, 0777, true);
Expand Down
2 changes: 1 addition & 1 deletion src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public function get_acf_type(string $type_name, array $config, array $field_grou
$final_type = ['list_of' => 'String'];
break;
case 'gallery':
$final_type = ['list_of' => 'MediaItem'];
$final_type = ['list_of' => 'ID'];
break;
case 'user':
$type = 'User';
Expand Down

0 comments on commit 5cd68f6

Please sign in to comment.