more code
This commit is contained in:
parent
e4a5ea0f99
commit
ffb833f00c
71
endpoints/add-fields.sh
Executable file
71
endpoints/add-fields.sh
Executable file
@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# example:
|
||||
#
|
||||
# add-fields.sh klimatologia4/web/modules/custom/src/Nodes.php manager string
|
||||
#
|
||||
#
|
||||
|
||||
C="\e[0;36m"
|
||||
R="\e[0;31m"
|
||||
G="\e[0;32m"
|
||||
B="\e[0;34m"
|
||||
W="\e[0;97m"
|
||||
E="\e[00m"
|
||||
|
||||
# Check parameters
|
||||
[ $# -ne 3 ] && echo 'Parameter missing' && exit
|
||||
|
||||
# Check Target file
|
||||
PHP="${1}"
|
||||
[ ! -f ${PHP} ] && echo 'File ${PHP} does not exist' && exit
|
||||
|
||||
# Field name
|
||||
NAME="${2}"
|
||||
|
||||
# Field source files
|
||||
TYPE="${3}"
|
||||
FIELD_DIR="/root/dev/endpoints/endpoint_get_fields/"
|
||||
ls -1 $FIELD_DIR | grep -E "${TYPE}_(extractor|response|splitter)" > /dev/null
|
||||
[ "$?" -ne 0 ] && echo -e "File for field ${R}${TYPE}${E} not found"
|
||||
|
||||
#
|
||||
# Iterate source files
|
||||
#
|
||||
for FILE in `ls -1 $FIELD_DIR | grep -E "^${TYPE}_(extractor|response|splitter)"`; do
|
||||
COMMENT=$(echo ${FILE} | awk -F_ '{print $2}')
|
||||
COMMENT=$(echo ${FILE} | awk -F_ '{print $2}')
|
||||
echo Adding 🍓 ${FILE} to 📦 $(basename ${PHP})
|
||||
done
|
||||
|
||||
exit
|
||||
comment="// FIELDS " ${}
|
||||
|
||||
exit
|
||||
new_code=$(cat << 'EOF'
|
||||
<?php
|
||||
// Your new code here
|
||||
$new_variable = 'New value';
|
||||
?>
|
||||
EOF
|
||||
)
|
||||
|
||||
|
||||
# Find the line number of the comment
|
||||
comment_line=$(grep -n "$comment" "$php_file" | cut -d ":" -f 1)
|
||||
|
||||
if [[ -n "$comment_line" ]]; then
|
||||
# Calculate the line number to insert the new code
|
||||
insert_line=$((comment_line + 1))
|
||||
|
||||
# Insert the new code into the PHP file
|
||||
awk -v insert="$insert_line" -v text="$new_code" 'NR == insert {print text} {print}' "$php_file" > tmpfile && mv tm
|
||||
pfile "$php_file"
|
||||
|
||||
echo "New code added successfully!"
|
||||
else
|
||||
echo "Comment not found!"
|
||||
fi
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
C="\e[0;36m"
|
||||
G="\e[0;32m"
|
||||
B="\e[0;34m"
|
||||
W="\e[0;97m"
|
||||
@ -11,12 +12,13 @@ MODULES="modules/custom"
|
||||
|
||||
SITE=${1}
|
||||
NODE=${2}
|
||||
IFS=$'\n'
|
||||
|
||||
function quit() {
|
||||
echo
|
||||
echo -e "Syntax:"
|
||||
echo -e "${W}./endpoint-get <drupal dir> <node type>${E}"
|
||||
echo
|
||||
echo
|
||||
echo -e "Example:"
|
||||
echo -e "${W}./endpoint-get mysite4 events${E}"
|
||||
echo
|
||||
@ -118,3 +120,19 @@ echo -e " - Permissions"
|
||||
echo -e " - Translations"
|
||||
echo -e " - Aliases"
|
||||
echo
|
||||
|
||||
function add_fields () {
|
||||
for FIELD in $(bash ./get-fields.sh ${SITE} node ${NODE});do
|
||||
FIELD_NAME=$(echo $FIELD | awk '{print $1}')
|
||||
FIELD_TYPE=$(echo $FIELD | awk '{print $2}')
|
||||
echo
|
||||
echo -en "Add field ${C}${FIELD_NAME}${E} of type ${C}${FIELD_TYPE}${E} ? [y/n] "
|
||||
read -n 1 response
|
||||
echo
|
||||
if [[ "$response" =~ ^([yY])$ ]]
|
||||
then
|
||||
echo do_something
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@ -71,7 +71,9 @@ class NodesController extends ControllerBase {
|
||||
$uid = $node->getOwnerId();
|
||||
$user = \Drupal\user\Entity\User::load($uid);
|
||||
$name = $user->getDisplayName();
|
||||
|
||||
//
|
||||
// FIELD_EXTRACT
|
||||
//
|
||||
/* BODY Field - absolute urls for body inline images */
|
||||
// $base_url = Url::fromRoute('<current>')->setAbsolute()->toString();
|
||||
// $url_components = parse_url($base_url);
|
||||
@ -117,6 +119,9 @@ class NodesController extends ControllerBase {
|
||||
'lang' => $node->get('langcode')->value,
|
||||
'alias' => $node->get('path')->alias,
|
||||
'author' => $name,
|
||||
//
|
||||
// FIELD_RESPONSE
|
||||
//
|
||||
// 'field_geolocation' => $field_geolocation,
|
||||
// 'field_link' => $field_link,
|
||||
// 'body' => $body,
|
||||
@ -147,6 +152,10 @@ class NodesController extends ControllerBase {
|
||||
return $nodes_response;
|
||||
}
|
||||
|
||||
//
|
||||
// FIELD_EXPLODE
|
||||
//
|
||||
|
||||
/*
|
||||
*
|
||||
* Multivalue fields
|
||||
|
||||
0
endpoints/endpoint_get_fields/entity_reference
Normal file
0
endpoints/endpoint_get_fields/entity_reference
Normal file
0
endpoints/endpoint_get_fields/file
Normal file
0
endpoints/endpoint_get_fields/file
Normal file
0
endpoints/endpoint_get_fields/image
Normal file
0
endpoints/endpoint_get_fields/image
Normal file
6
endpoints/endpoint_get_fields/string-extractor
Normal file
6
endpoints/endpoint_get_fields/string-extractor
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
$FFFFF = '';
|
||||
if ($node->hasField('FFFFF') && !$node->get('FFFFF')->isEmpty()) {
|
||||
$manager = $node->get('FFFFF')->value;
|
||||
}
|
||||
|
||||
1
endpoints/endpoint_get_fields/string-response
Normal file
1
endpoints/endpoint_get_fields/string-response
Normal file
@ -0,0 +1 @@
|
||||
'FFFFF' => $FFFFF,
|
||||
0
endpoints/endpoint_get_fields/string_long
Normal file
0
endpoints/endpoint_get_fields/string_long
Normal file
0
endpoints/endpoint_get_fields/text_with_summary
Normal file
0
endpoints/endpoint_get_fields/text_with_summary
Normal file
32
endpoints/get-fields.sh
Executable file
32
endpoints/get-fields.sh
Executable file
@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# example:
|
||||
#
|
||||
# ./get-fields.sh klimatologia4 node edition
|
||||
#
|
||||
# body text_with_summary
|
||||
# field_author string
|
||||
# field_file file
|
||||
#
|
||||
|
||||
IFS=$'\n'
|
||||
DIR=$1
|
||||
TYPE=$2
|
||||
NAME=$3
|
||||
|
||||
cd /var/www/sites/$DIR
|
||||
|
||||
for FIELD in $(vendor/drush/drush/drush fi ${TYPE} ${NAME} | tail -n +3 | grep -v '\-\-\-'); do
|
||||
NAME=$(echo $FIELD | awk '{print $1}')
|
||||
TYPE=$(echo $FIELD | awk '{print $2}')
|
||||
COUNT=$(echo $TYPE | wc -c)
|
||||
THIRD=$(echo $FIELD | awk '{print $3}')
|
||||
|
||||
if [ "$COUNT" -lt 5 ] && [ -z "${SECOND// }" ]; then
|
||||
TYPE=$THIRD
|
||||
fi
|
||||
|
||||
echo "$NAME $TYPE"
|
||||
done
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
IFS=$'\n'
|
||||
DIR=$1
|
||||
TYPE=$2
|
||||
NAME=$3
|
||||
|
||||
cd $DIR
|
||||
|
||||
for FIELD in $(vendor/drush/drush/drush fi ${TYPE} ${NAME} | tail -n +3 | grep -v '\-\-\-'); do
|
||||
NAME=$(echo $FIELD | awk '{print $1}')
|
||||
SECOND=$(echo $FIELD | awk '{print $2}')
|
||||
THIRD=$(echo $FIELD | awk '{print $3}')
|
||||
COUNT=$(echo $SECOND | wc -c)
|
||||
|
||||
if [ "$COUNT" -gt 5 ]; then
|
||||
TYPE=$SECOND
|
||||
else
|
||||
TYPE=$THIRD
|
||||
fi
|
||||
|
||||
echo "$NAME $TYPE"
|
||||
done
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user